-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccess-elements.js
More file actions
29 lines (24 loc) · 781 Bytes
/
Copy pathaccess-elements.js
File metadata and controls
29 lines (24 loc) · 781 Bytes
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
// Getting Elements
const body = document.body;
const images = document.images;
const links = document.links; // <a> && <area> with href
const anchors = document.anchors; // a with name
const forms = document.forms;
// By id
// if('') return null
const h1 = document.getElementById('title');
// By tag name
// returns live node list || []
const listItems = document.getElementsByTagName('li');
// By class
// returns live node list || []
// IE support >=9
const heroes = document.getElementsByClassName('hero');
// By CSS selector
// can be used on elements, not just document
// returns 1st match || null
// IE support >=8
document.querySelector('#bats');
ul.querySelector('li#bats'); // $('ul').find('li#bats');
// returns node list || []
document.querySelectorAll('.hero');