Skip to content

Instantly share code, notes, and snippets.

@garethfoote
Created May 2, 2017 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garethfoote/51dd7c1dbd7521c1e94ae068fe7d0224 to your computer and use it in GitHub Desktop.
Save garethfoote/51dd7c1dbd7521c1e94ae068fe7d0224 to your computer and use it in GitHub Desktop.
JavaScript - DOM Selection & Manipulation
<!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