echan00
echan00

Reputation: 2807

Javascript call Remove() twice to remove element

I'm running into a weird event where I must call remove() twice to remove an element. Below I've pasted my javascript console, you can see that I need to call remove twice to remove the element.

$("#products-view-17")
[
<div class=​"product-tile" id=​"products-view-17">​…​</div>​
]

$("#products-view-17").remove()
[
<div class=​"product-tile" id=​"products-view-17">​
<a href=​"http:​/​/​www.shopify.com" target=​"_blank">​…​</a>​
<div id=​"associate_form" class=​"remove_button">​…​</div>​
</div>​
]

$("#products-view-17")
[
<div class=​"product-tile" id=​"products-view-17">​
<a href=​"http:​/​/​www.shopify.com" target=​"_blank">​…​</a>​
<div id=​"associate_form" class=​"remove_button">​…​</div>​
</div>​
]

$("#products-view-17").remove()
[
<div class=​"product-tile" id=​"products-view-17">​
<a href=​"http:​/​/​www.shopify.com" target=​"_blank">​…​</a>​
<div id=​"associate_form" class=​"remove_button">​…​</div>​
</div>​
]

$("#products-view-17")
[]

Other elements on my page have no problem, one Remove() call does it. Only those that are dynamic generated here are problematic. This used to work fine, what could possible have broken it?

Upvotes: 1

Views: 1250

Answers (2)

Coder
Coder

Reputation: 220

Since there is a problem with the library as mentioned by you.Check the following work around for removing multiple elements with same id

 $('[id^="products-view-17"]').remove();

Upvotes: 3

echan00
echan00

Reputation: 2807

There was in fact two elements of the exact same ID. Although only one copy on the page, this is the culprit: https://github.com/okendoken/bootstrap-tabcollapse

Upvotes: 0

Related Questions