[jQuery] stripping out tags...
Hi there...
I was about to ask how to strip a tag from the DOM.
For example we have this:
<div id="someId">
<label for="someFor">some <span>text</span> here</label>
</div>
I want to remove the <label> tag and preserve what it contains.
But while I was writing my question, I came up with this:
jQuery.fn.stripOut = function (el) {
$(this).each( function(){
$(this).find(el).parent().html(($(this).find(el).html()));
})
}
so we can do:
$("#someID").stripOut("label");
This will produce:
<div id="someId">
some <span>text</span> here
</div>
But I see a tiiiiiny problem here...
If we have for example:
<div id="someId">
some div text
<label for="someFor">some <span>text</span> here</label>
some div text
</div>
with my stripOut() the text "some div text" together with all the eventual
siblings of the <label> tag will go pooof.
I'm not good at the coding, so can somebody help me with a better solution?
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/