JQuery class selector vs id selector

后端 未结 5 628
天涯浪人
天涯浪人 2020-12-16 17:31

I have 7 different buttons that all perform the same javascript function on click. should i use class selector or id selector.

$(\"input.printing\").on(\"c         


        
5条回答
  •  悲哀的现实
    2020-12-16 17:58

    Obviously your first code using class is much cleaner, neater and better.

    ID selector are the fastest, which is true.. but at this time and age, it doesn't really matter.

    So don't get bothered so much with performance(unless it is a concern) and just use the one that is clean and maintainable.

    oh btw, you don't even need that anonymous function. See below,

    $("input.printing").on("click", printPdf);
    

提交回复
热议问题