Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Get Text Node with Dojo JS

I am trying to get the text from within a tag - but that tag has a nested node, too which I don't want. How do I just get the text?

For example

<div id="i_want_the_text_in_this_div">
  <span id="but_not_this_one">
   ignore this text
  </span> 
  keep this text
</div>
like image 852
voidstate Avatar asked Jan 22 '23 09:01

voidstate


2 Answers

Try: dojo.query('#i_want_the_text_in_this_div')[0].lastChild.textContent;

like image 182
pp19dd Avatar answered Feb 03 '23 03:02

pp19dd


Use dojo.attr(node, 'innerHTML') as textContent does not work in IE

like image 43
Alfredo Carrillo Avatar answered Feb 03 '23 03:02

Alfredo Carrillo