Javascript Tech Pile Notes
Javascript Tech Pile Notes
Javascript Tech Pile Notes
Window
--------
Window is the predefine primary object of javaScript.
It provides some methods(functions) and property(variables).
Object
-------
Object Properties
The name:values pairs in JavaScript objects are called properties:
objectName.propertyName
or
objectName["propertyName"]
Methods are actions that can be performed on objects.
A method is a function stored as a property.
What is this?
INJavaScript, the this keyword refers to an object .
Accessing Object Methods
You access an object method with the following syntax:
objectName.methodName()
Example
name = person.fullName();
x = new String(); // Declares x as a String object
y = new Number(); // Declares y as a Number object
z = new Boolean(); // Declares z as a Boolean object
prompt:
---------
=>prompt function is used to take input form the user at RunTime.
=> return type is string
=> OK means True
=> Cancel mean False
Syntax
--------
Var variable = prompt("FielsName", "placeholder")
var name = prompt("Name", "Enter your name")
Type Casting
----------------
Convertion of one DataType value into Another Datatype call type casting
1. parseInt()
2. parseFloat()
3. Number()
4. String()
5. toString()
Conform():
--------------
Is use to Take conformation with the user.
: It has Two button(Ok, Cancel)
getElementById():
------------------
=> getElementById() function is used to select html element on the basis on Id.
=> It is defined inside the Document Object.
=> return type of getElementById is Current Object.
Syntax
--------
=> document.getElementById("IdOf HtmlElement")
let varName = document.getElementById("x");
Steps to Apply CSS with JS.
--------------------------------
Object.style.propertyName = "Value"
get
------
var X = parseInt(document.getElementById("txt").value);
function demo1() {
let x = document.getElementById("num").value;
console.log(parseInt(x));
}
Set
-------
var x1 = document.getElementById("txt").value;
var x2 = document.getElementById("idOfFormControl").value;
x1.value = x2;
write
------
=> write function is used to display o/p on the html document
=> it is define inside the document object.
Syntax
--------
document.write(message);
innerText
-----------
innerText is used to set/get normal text of selected HTML element.
<div id="dv"> </div>
get/set
----------
let var = document.getElementById("dv").innerText
let var = document.getElmentById("dv").innerText="SetValue"
------------------------------------------------------------
Location (Variable) :
=> location property is used to redirect one page to another page.
Syntax
--------
window.location ="URL"
Src property
-----------------
=> Src property is used to set/get the value of Src Attribute
Syntax
--------
<img src="a.jpg" id="img1" />
get
------
var x = document.getElementById("img1").src;
set
-----
document.getElementById("img1").src=" image Url";
SetInterval :
--------------
window.setInterval(function,ML Second);
when
setInterval(demo,1000);
setInterval("demo()", 2000);
1 second => 10000 ml second
querySelector :
-----------------
document.getElementById("Id")
{
#IdNAme
.ClassName
TagName
}
document.querySelector("#ID")
document.querySelector(".ClassName")
document.querySelector();
setTimeOut
-----------
=> setTimeout function is used to Execute a once group of statement after
given time interval.
=> Function will call one specific time
Syntax :
----------
window.setTimeout("functionName()", time in ML )
innerHTML
----------
innerHTML is used to Set/get text with Tag of selected HTML element.
Type Property :
----------------
Type property is used to set/get value of type attribute
of selected form control.
Syntax: get/set
--------
let x = document.querySelector(".password").type;
let y = document.querySelector(".password").type="text";
Strick Equal === It will check type and value == it will check value only
---------------------------------------------------------------------------
setAttribute("AtrributeName","value")
-------------------------------------
document.querySelector("Element name").setAttribute("attributeName","value");
let demo= ()=>
{
document.querySelector("img").setAttribute("src","images/a.jpg");
}
<img onclick="demo()" src="images/b.jpg" class="m1" />
var x = document.querySelector("img").getAttribute("src");
RemoveAttribute :
-----------------
Syntax
---------
let x = document.querySelector("img").hasAttribute("class")
Print :
------------
<div id="bx">
<img src= "url" />
</div>
const x = document.querySelector("#bx").innerHTML;
document.body.innerHTML = x;
window.print(x);7
Array in JavaScript :
----------------------
var arr = [10,20,30,40,'kittu', 'true'];
for loop:
----------
for(int i=0; i<=10; i++){}
getElementByTagName()
------------------------
=> Used to select all matches element(Tags) in form the array.
=>
Syntax :
----------
let x = document.getElementByTagName("Tag").innerText
=> Return object collection of array of similar tag.
Date Class :
---------------
let obj = new Date();
Date Class Methods :
--------------------
=> getDate()
=> getTime()
=> getWeek()
=> getDay()
=> getMonth()
=> getFullYear()
=> getHours()
=> getMinutes()
=> getSeconds()
=> getMiliseconds()
Anonymoush function
---------------------
we used anonymous function inside other function
normal :
--------
function ()
{
}
Arrow anonoymous function function:
-----------------------------------
We used call back function to call anonymous function
()=>
{
Keyword Events :
-----------------
1. onkeypress : It will call before enter any value in input box. Before Typing
2. onkeyup : It will call after enter some value in input box. After Typing
3. onFocus : It will call when cursur enter in Input Box. Call When Enter input
box.
4. onBlur : It will call when Cursur leave the Input Box. Call When Leave Input
box.
pinCode Vaidation :
--------------------
find the lenth of Input value apply if else apply Text red Color
GetElementsByClassName :
-------------------------
It is used to return by HTMLCollection with specificd ClassName.
by useing get all tags collection where one class call tags inside.
Syntax :
--------
ForEach()
----------
if we want to execute of function for every elment present in collection.
EX : (ARRAY, NodeList)
AddEventListner