Monday, August 20, 2012

html – How to get text from an element with other children using jQuery

I have something similar to the following:



<div>
Hello World
<div>Something Else</div>
</div>


I want to use javascript/jQuery to get just the \’Hello World\’ text.

I could just wrap it in a span and select that, but I now want to know how to do this.


I thought simply using $(\’div\’).text() would work, but it gives me \”Hello WorldSomething Else\”.


Thanks,

Matt






Rating: 5 out of 5 based on 5 ratings



The post html – How to get text from an element with other children using jQuery appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/html-how-to-get-text-from-an-element-with-other-children-using-jquery.html

No comments:

Post a Comment