Reduce the amount of jquery selectors being used to speed up interactions
I have a page that has m开发者_开发知识库ultiple selectors. Each has an on click event. I was just wondering was there a way to combine these selectors or even do a global selector and have jQuery find what was clicked?
"Do a global selector and have jQuery find what was clicked?"
$('select').click ( function () {
console.log ('A ', this.nodeName, ' was clicked\n',
'It had an id of: ', this.id
);
/* Etc., etc. You can use jQuery or standard DOM to
tell most anything about the element that was clicked.
*/
} );
If i understood your question right, what you want to do is group them by giving them a class .my_selector_class.
Then add a click event
$('.my_selector_class').click(function(){
})
and work with the $(this)
selector inside, to only reflect changes on the actual clicked element.
The most this does for performance though, is to speed up pages loading times by reducing the bytes to be fetched on load.
精彩评论