Last active
September 15, 2017 21:27
-
-
Save ripter/700cda9ff64960c29fa5b928eee901cc to your computer and use it in GitHub Desktop.
DOM Attributes Example
This file contains hidden or 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
| const a = document.getElementsByTagName('a')[0]; // get <a> from the example html | |
| const p = document.getElementsByTagName('p')[0]; // get <p> from the example html | |
| // Get/Read Attributes | |
| a.attributes.href; // returns NamedNodeMap href="//github.com" | |
| a.getAttribute('href'); // returns "//github.com" | |
| // Set/Write Attributes. | |
| p.attributes.style.value = 'color: green;'; // set the attribute value. | |
| p.setAttribute('style', 'color: white;'); // set the inline style |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment