How do i extract the text part of a div leaving out text of inner html tags
Here is the div
<div class="MessageBox">I want to see only this message<span....>Click Here to collapse</span></div>
Here is the jquery inside a javascript function
var message= $(".MessageBox").text();
Right now i am getting
message= “I want to see only this message Click Here to collapse”
I want message =”I want to see only this message”
You can use the
clone()method to clone the main element, then remove the children of that clone in order to discard the parts you don’t want:You could, of course, skip the cloning part. But then you’d actually be removing the elements from the page, and I’m not sure that you want to do that. Cloning the main element allows you to then manipulate a copy of it, rather than the one the user actually sees.