views:

49

answers:

2

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 the 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();

                            });
A: 

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/

Marko
Ahh you decided to post some code after all. My answer is pointless then. Nevermind.
Marko
+2  A: 

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();
mattbasta
hey thanks. This worked out for me. But how will I remove the BR tag along with the SPAN tag removed ?
Sreejesh Kumar
But how will I remove the BR tag along with the SPAN tag removed ?
Sreejesh Kumar
Ok. I got it. I removed that too.
Sreejesh Kumar