Question

Given HTML of this form:

<div>
    <a href="#">Generic Anchor</a>
    <li> Some text </li>
    <b> More stuff </b>
    Just text.
</div>

Where the tags are random, is there a way in jQuery (or Javascript) to reduce it to ONLY the text, meaning

<div>
    Just text.
</div>

Without having to specify particular tags to strip (I'm aware of .text(), but I don't want the contents of the tags I'm removing).

Was it helpful?

Solution

Try this: http://jsfiddle.net/5SRLE/1/

$("div").children().remove();

Of course, you'll want to target the specific div with that selector (if you have other divs that you don't want to remove children from). If you have problems, show your context so we can make it more specific... or give your div an id like myDiv and then use the selector $("#myDiv") in place of $("div")

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top