Created
May 2, 2017 16:16
-
-
Save garethfoote/51dd7c1dbd7521c1e94ae068fe7d0224 to your computer and use it in GitHub Desktop.
JavaScript - DOM Selection & Manipulation
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title>JavaScript Example</title> | |
</head> | |
<body> | |
<h1>This is a JS Example.</h1> | |
<span class="time">What's the time?!</span> | |
<hr/> | |
<span class="name">What's my name?!</span> | |
<script> | |
// Get the HTML tag with class="time" | |
var timeElement = document.querySelector(".time"); | |
// Look out the HTML tag | |
console.log(timeElement); | |
// Create a new timedate object. | |
var time = new Date(); | |
// Change the content of the HTML tag to the current time. | |
timeElement.textContent = time.toString(); | |
// Add your name to the HTML tag. | |
var nameElement = document.querySelector(".name"); | |
console.log(nameElement); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment