Last active
September 18, 2017 07:32
-
-
Save imparvez/cc298ad540ecf8828f4e7780c13f4a5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<div class="wrapper"> | |
<h1 class="header" id="header">This is Header</h1> | |
<a href="#" id="anchor" class="anchor-link">CLICK ME</a> | |
<p>lorempixel lorempixel lorempixel lorempixel lorempixel lorempixel lorempixel lorempixel lorempixel lorempixel lorempixel lorempixel lorempixel lorempixel lorempixel | |
lorempixel lorempixel lorempixel lorempixel lorempixel | |
lorempixel lorempixel lorempixel lorempixel lorempixel | |
</p> | |
<a href="#" id="anchor" class="anchor-link">CLICK ME</a> | |
<h1 class="header" id="header">This is Header</h1> | |
<a href="#" id="anchor" class="anchor-link">CLICK ME</a> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var headerId = document.getElementById('header'); | |
console.log('headerId => ', headerId) // HTML Collection | |
// If header element appears more than one, headerClass will be of length `1` only. | |
var headerClass = document.getElementsByClassName('header'); | |
console.log('headerClass => ', headerClass); // Node List | |
// If header element appears more than one, headerClass will be of length `2` | |
// Access desired header element | |
var headerClassFirst = document.getElementsByClassName('header')[0]; | |
console.log('headerClassFirst => ', headerClassFirst); // HTML Collection | |
var headerQuerySelector = document.querySelector('.header'); | |
console.log('headerQuerySelector => ', headerQuerySelector); // HTML Collection | |
var headerQuerySelectorAll = document.querySelectorAll('.header'); | |
console.log('headerQuerySelectorAll => ', headerQuerySelectorAll); // Node List | |
// If header element appears more than one, headerQuerySelectorAll will be of length `2` | |
var anchorTagName = document.getElementsByTagName('a'); | |
console.log('anchorTagName => ', anchorTagName); // Node List | |
// If anchor element appears more than one, anchorTagName will be of length `2` or `more` | |
// References: https://plainjs.com/javascript/selecting/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment