-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGet & Set Methods.ja
36 lines (24 loc) · 1.25 KB
/
Get & Set Methods.ja
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//show you all the text that is present in your html tag.
// should only be used with ID not with class.
let x = document.getElementById("maincontent").innerText;
console.log(x);
//show you all the HTML that is present in your id.
// should only be used with ID not with class.
let x = document.getElementById("maincontent").innerHTML;
console.log(x);
// get attribute shows you the value of your attribute that is used in any id.
// let's take and example.
// in getAttribute you have to pass the attribute name you want the value of.
let attrValue = document.getElementById("maincontent").getAttribute("class");
console.log(attrValue);
// getAttributeNode prints the value both attribute and there value as well.
// let's take an example.
let nodeAttr = document.getElementById("maincontent").getAttributeNode("class");
console.log(nodeAttr);
// attributes prints all the attribute that is used inside a tag in the form of an array.
// you can print any attribute value and name by using .value and .name method.
let attr = document.getElementById("maincontent").attributes;
console.log(attr);
// now if i wanna see any specific attribute value or name then i will use.
let attr1 = document.getElementById("maincontent").attributes[2].value;
console.log(attr1);