In my page, due to some reason (which I do not find relevant to the topic hence not explaining) a div gets duplicated and two divs with same id are generated in my html. While writing jquery code to remove all divs except topmost, I found that $("#id")
was returning me just 1 element(note: there are two divs with same id now) whereas $("[id=]")
was returning me 2
. So finally my code worked with $("[id=]")
but not with $("#id")
.
Any reason why? Is it that $("#id")
returns only the first element it finds with specified id?
Please note that I have already come across a thread which has a similar question but does not answer my query