javascript - DOM access to different elements -
i’m trying learn how different levels of dom javascript, once i’ve made initial entry point. example, if want access following div element, target attribute:
var divcontent = document.getelementbyid(‘box_1’);
how access li tags? ultimately, want write event handler populate li tags, first need know how access them via id attribute div.
<div id="box_1"> <ul> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> <li></li> </ul>
guess what: can elements tagname
, having id parent node. cool, han?
var parent = document.getelementbyid('box_1'), children = parent.getelementsbytagname('li'); // gets children of parent
now need iterate on child 'li' nodes
var i, e; (i = 0; < children.length; ++i) { e = children[i]; //do magic e }
Comments
Post a Comment