I am new to HTML DOM operations. I failed even for simple examples.
Here are my codes:
<h1>head 1</h1>
<h2>head 2</h2>
<script type="text/javascript">
var h1 = document.getElementsByTagName('h1');
alert("tagName : "+h1.getTagName());
h1.parentNode.removeChild(h1);
</script>
<h3>head 3</h3>
The above codes even don’t pop out any “alert”.
I also tried:
alert("nodeType: "+h1.nodeType);
alert("nodeName: "+h1.nodeName);
alert("nodeValue: "+h1.nodeValue);
alert("tagName: "+h1.tagName);
However, they all response undefined.
This site is really useful.
http://www.w3schools.com/jsref/dom_obj_node.asp
Once you get a grasp of it, be sure to use jquery or some other library for working with dom (makes life easier):
http://jquery.com/