- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_getAttribute.js
More file actions
Latest commit
20 lines (17 loc) · 639 Bytes
/
Copy path10_getAttribute.js
File metadata and controls
20 lines (17 loc) · 639 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// getAttribute();
// setAttribute();
constheading=document.querySelector('.title');
// getAttribute class and id from h2
constclassValue=heading.getAttribute('class');
constidsValue=heading.getAttribute('id');
console.log(classValue);// show title class
console.log(idsValue);//show titles id
// setAttribute
// first move to p cz no have class
constnextoP=heading.nextElementSibling.nextElementSibling;
nextoP.setAttribute('id','text');
nextoP.textContent='This is a text';
// example again showLinks
constlinks=document.querySelector('.links');
constgetLinks=links.getAttribute('href');
console.log(getLinks);