Reputation: 640
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
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