javascript - How to select text by tag name in element? -


i need select title in div wrapped h2, this.getelementsbytagname('h2') current div in h2 - returns current h2 element, when trying innerhtml or innertext return null. doing wrong?

it returns current h2 element, when trying innerhtml or innertext return null. doing wrong?

getelementsbytagname returns nodelist, not element. list doesn't have innerhtml, each of elements does, e.g.:

var list = this.getelementsbytagname('h2'); if (list[0]) {     title = list[0].innerhtml; } 

or if you're sure exist:

title = this.getelementsbytagname('h2')[0].innerhtml; 

...but throw exception if there no h2's found.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -