I want to set so many attributes for multiple elements. Javascript always give better performance when comparing to jquery.
i want to know which one gives better performance when settling multiple attributes via jquery and javascript.
Jquery multiple attribute setter:
$(element).attr({'id': 'id1', 'index':1, 'value':10,'check':'checked'});
using javascript setAttribute :
element.setAttribute('id','id1');
element.setAttribute('index','1');
..................................
when am using javascript i need to write multiple lines. otherwise need to create custom function for this.
can anyone explain which one gives better performance ? and why ?
Thanks,
Siva
.attr()way is the way to go..data(). As for the HTML defined properties, vanilla will likely be faster since you have so many elements. Use jsperf.com to know the exact performance implications.