JavaScript match error -
i have following code
var list = document.getelementsbytagname("section"); var counter=0; var output = ""; (var i=0; i<list.length; i++) { if ( list[i].classname.match(/\bmodule\b/) ) { var header_text = list[i].getelementsbytagname("h2")[0].innertext; var ul = list[i].getelementsbyclassname('clips'); var li_list = ul[0].getelementsbyclassname('title'); if ( li_list.length > 1 ) { output += "------" + header_text + "------" + " "; (var y=0; y<li_list.length; y++) { counter += 1; output += counter + " - " + li_list[y].innertext + " "; }}}} console.log(output); and getting error: uncaught typeerror: cannot read property 'match' of undefined. know why happening?
thanks
edit: prasad's answer fixed initial problem getting similar issues getelementsbytagname , getelementsbyclassname
edit: general structure of html following
<body> ... <section class="module"> <header class> <div></div> <div class="side-menu-module-title"> <h2 class="..."></h2> </div> </header> </section> ... </body>
you missing i on iterating element.its list[i]
for (var i=0; i<list.length; i++) { if ( list[i].classname.match(/\bmodule\b/) ) {
Comments
Post a Comment