Temporary remove in jQuery -
<div class="stuff"> <span class="to_hide"> blah </span> <span id="permanent"> glue </span> </div>
i want grab $(".stuff").text()
, don't #tmp
's text
this works fine $(".to_hide").remove()
but don't want removal action have effect on page itself. if remove or detach, need know elements have been (assume many .to_hide
nodes)
how can use .text()
while ignoring .to_hide
one easy way use clone
var text = $(".stuff").clone().find('.to_hide').remove().end().text(); console.log(text)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="stuff"> <span class="to_hide"> blah </span> <span id="permanent"> glue </span> </div>
you can - if have complex systems , text nodes direct descendants of stuff
may not work
var text = $(".stuff *").not('.to_hide').text(); console.log(text)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="stuff"> <span class="to_hide"> blah </span> <span id="permanent"> glue </span> </div>
Comments
Post a Comment