What’s the difference between class and id in jQuery?

ID’s should be unique on the page, when you have multiple elements with same ID’s, jQuery selects only the first one. That’s because it doesn’t have to bother looking for others as there isn’t supposed to be any more – that might explain the weird behaviour you’re experiencing.

If you want multiple elements to have the same functionality, give them the same class. If you want to identify a specific element, give it an id. This isn’t limited to just jQuery, but to HTML and CSS overall.

Leave a Comment