Reputation: 38422
I have the following code :
$('.TopNotificationIcon span').remove();
Can I replace .TopNotificationIcon
with this
i.e only span
exists inside this specific class.
This is the structure
<div class="TopNotificationIcon"><span>xxxxx</span></div>
On click of .TopNotificationIcon
, span
should be removed.
Upvotes: 16
Views: 24416
Reputation: 20415
I would use the find() method, as it seems to be the fastest:
$("div.TopNotificationIcon").click(function() {
$(this).find("span").remove();
});
Upvotes: 15
Reputation: 1527
If you want to remove all span under TopNotification you can do this :
$('div').live('click', function(){
$(this).children('span').remove();
});
It will remove all children in a div.
Upvotes: 4
Reputation: 1038
Yes but youd need to change the line to:
$(this).children('span').remove();
js fiddle: http://jsfiddle.net/UNhhh/1/
Upvotes: 3
Reputation: 1629
Try this...
$('span').remove('.TopNotificationIcon');
This will remove all span elements with the class TopNotificationIcon and also child elements
Upvotes: 2
Reputation: 14390
if you have click event for .TopNotificationIcon
you can do something like this
$('.TopNotificationIcon').click(function(){
$('span',this).remove();
});
Upvotes: 19