JQuery element [attribute = something] versus element.class performance

I am wondering which path will end faster by selecting the elements:

$('element[href=#my_link]'); 

or

 $('element.my_class'); 

I don’t like to repeat myself when I write code, so I prefer to write it in the first way for the most part, because then I can add information to it, for example:

 <a href="#delete_1">Delete</a> $('a[href^=#delete]'); 

and then separate it so that I have all the information I need after clicking it or whatever it is. Because of this, am I sacrificing overall efficiency?

(I think I could rewrite it as class = "delete" href = "# 1")

0
source share
1 answer
  • item selection by classes: 453 ms
    • element selection by element + search takes 578 ms

both in firefox.

Check out this great webpage for more tests:

Jquery performance

+3
source

All Articles