Farok Ojil Farok Ojil - 1 year ago 154
jQuery Question

jquery - get text for element without children text

for example we have this file

<div id="mydiv">
some text here
<div id="inner div">
text for inner div

i need to get
text only with some code like this :

alert($('#mydiv').text()); // will alert "some text here"

Answer Source

hey try this please": http://jsfiddle.net/MtVxx/2/

Good link for your specific case in here: http://viralpatel.net/blogs/jquery-get-text-element-without-child-element/ (This will only get the text of the element)

Hope this helps, :)


jQuery.fn.justtext = function() {

    return $(this).clone()


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download