Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with $.remove() in jQuery

To put it simple...

I have element clone. Its div with some other tags saved in it. It also have .x in it.

I need to remove it and then apped that modified element to another element.

Unfortunately, it doesn't work. Remove failed or something, but .x is still in it.

clone = subtitle.clone(); // Works!
no_label = clone.remove('.x'); // This fails.
more_subtitles.append(no_label); // Its appends no_label, but it still contains .x element.
like image 959
daGrevis Avatar asked Mar 16 '26 21:03

daGrevis


1 Answers

That's because remove() removes the matched elements from the DOM. Even if you pass a selector, it's only used to filter these elements. In your code, clone matches a single element (the cloned subtitle) which doesn't expose the x class.

You can use find() to match the .x element:

more_subtitles.append(subtitle.clone().find(".x").remove().end());
like image 132
Frédéric Hamidi Avatar answered Mar 18 '26 10:03

Frédéric Hamidi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!