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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -