Created
September 14, 2012 15:23
-
-
Save bmakarand2009/3722600 to your computer and use it in GitHub Desktop.
Javascript DOM 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> | |
<script> | |
var aElement = document.getElementById("intro"); | |
//Properties that can be invoked on aElement are | |
/* | |
x.innerHTML - the text value of x | |
x.nodeName - the name of x | |
x.nodeValue - the value of x | |
x.parentNode - the parent node of x | |
x.childNodes - the child nodes of x | |
x.attributes - the attributes nodes of x | |
*/ | |
var initialText = aElement.innerHTML;//can also do aElement.node[0].nodeValue; | |
aElement.innerHTML = "<p> Lets add some intro to the paragraph" + initialText+ "/p>"; | |
var nodeList = document.getElementsByTagName("div"); | |
//other methods that can be invoked on aElement are | |
// x.getElementById(id) - get the element with a specified id | |
// x.getElementsByTagName(name) - get all elements with a specified tag name | |
// x.appendChild(node) - insert a child node to x | |
// x.removeChild(node) - remove a child node from x | |
// | |
console.log("myotherNodeLis size is" + myohterNodeList); //returns 1 | |
console.log("nodelist size is" + nodeList.length); //returns 2 | |
</script> | |
</head> | |
<body> | |
</html> | |
<p id="intro">Hello World!</p> | |
<div class="mytop"> | |
<p> This is the first para </p> | |
<p> This is the second para </p> | |
<div> | |
This is one more div </div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment