javascript - How to get the text in a particular div only avoiding the text from nested divs? -


i have nested div structure follows

    <div id =a>       content     <div id =a1>       irrelevant content     </div>      <div id= a2>       irrelevant content     </div>      </div> 

i know can innertext of div id "a" document.getelementbyid('a').innertext give me my content irrelevant content irrelevant content want content in particular div instead of concatenated contents of nested divs.how it?

loop on direct child nodes , filter called 'text nodes' (i.e. contain text, , not tags).

var element = document.getelementbyid('a'), result = ""; (var i=0; i<element.childnodes.length; ++i) {     if (element.childnodes[i].nodetype === 3) {         result += element.childnodes[i].textcontent;     } } 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

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