开发者

remove SPAN and BR in DIV

I have filled data enclosed in a SPAN tag and BR tag for line break, in a DIV control. From the DIV, I wanted to remove a patricular text, ie removing the whole SPAN and BR associated with the text too using jquery or javascript. I tried .remove() in jquery. It seems not working. I dont know what is t开发者_如何学Che correct way.

The script I used for removing the SPAN related to the ID and BR is as follows :

$("#<%=divMeasures.ClientID %>").find("SPAN[id=" + draggedNodeID + "]").each(function() {
                                $(draggedNodeID).remove();

                            });


It's hard to diagnose without code, but try something like this:

$("div span,div br").remove();

You can replace div with a selector that better describes your div element, like an ID:

$("#mydiv span, #mydiv br") // ...

Hope this helps!

Edit

Based on your new code, try this:

$("#<%=divMeasures.ClientID %> span#" + draggedNodeID).remove();


It sound like you're trying to match an element by searching for a string and then remove that element.

So let's say your div was called someDiv, and you had lorem ipsum text inside a few spans, like so:

<div id="someDiv">
    <span>lorem ipsum dolor sit amet, consectetur adipiscing elit.</span>
    <span>Vivamus in sapien ut urna aliquam gravida eu nec sapien. </span>
    <span>Phasellus quis velit sit amet neque dapibus fringilla. </span>
    <span>Donec eget lorem sed sapien porttitor tincidunt quis aliquet lacus.</span>
</div>

Then in jQuery, I want to find the word "lorem" and remove that text.

$("#someDiv span:contains('lorem')").remove();

You can read more about the remove method on the official jQuery website. http://api.jquery.com/remove/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜