Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript get only div parent node value(without child nodes)

Here is my problem:

<html>
    <div id="parentdiv">
        some parent value
        <div id="childdiv">some child value</div>
    </div>
</html>

parent div --> parent div content --> child div --> child div content --> end child div --> end parent div

I need to acquire only parent div value, without child div value. How can I do that in Javascript?

like image 958
user2107321 Avatar asked Nov 04 '22 03:11

user2107321


1 Answers

try this:

alert($('#parentdiv').clone().children().remove().end().text());
like image 159
gregjer Avatar answered Nov 09 '22 13:11

gregjer