Last active
January 15, 2020 15:16
-
-
Save mohammadYousefiDev/79f165a1ef3b355a206ea0304abba224 to your computer and use it in GitHub Desktop.
1. access to element in javascript
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
<html> | |
<head></head> | |
<body> | |
<p name="codepenName" id="codepenID" class="codepenClass">Hello World</p> | |
<script> | |
//way1 | |
/* | |
var x = window.document.getElementById('codepenID') | |
x.style.color = 'blue' | |
*/ | |
//way2 | |
/* | |
var x = window.document.getElementsByTagName('P') | |
x[0].style.color = 'blue' | |
*/ | |
//way3 | |
/* | |
var x = window.document.getElementsByClassName("codepenClass") | |
x[0].style.color = 'red' | |
*/ | |
//way4 | |
/* | |
var x = window.document.getElementsByName('codepenName') | |
x[0].style.color = 'green' | |
*/ | |
//way5 | |
/* | |
var x = window.document.querySelector('#codepenID') | |
x.style.color = 'green' | |
*/ | |
//way6 | |
/* | |
var x = window.document.querySelectorAll('p') | |
x[0].style.color = 'red' | |
*/ | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment