Evlikosh Dawark
Evlikosh Dawark

Reputation: 640

How to remove a span from list by span's class name by jquery

I'm dynamically appending a span class to an li element

li_element.append("<span class='delay_loading'><img id='delay_ajax-loader' style='display:none;' src='/static/img/ajax-delay.gif' /></span>")

How can I remove the added span class by its class name?

Upvotes: 4

Views: 11759

Answers (2)

nickf
nickf

Reputation: 546005

Yep, you just have to find() it first. Because you know that it'll be a direct child of the li_element, you can use children() which will be faster:

li_element.children(".delay_loading").remove();

However, a better idea might be to keep a reference to it in the first place:

var span = $("<span class='delay_loading'><img ... ></span>").appendTo(li_element);

// later, when your loading is done:
span.remove();

Upvotes: 1

Aram Mkrtchyan
Aram Mkrtchyan

Reputation: 2700

$('.delay_loading').remove();

Upvotes: 5

Related Questions