How can I select an element by ID with jQuery using regex?

前端 未结 7 1693
执念已碎
执念已碎 2020-11-28 05:51

I have the following input elements:




        
7条回答
  •  孤城傲影
    2020-11-28 06:37

    I use to solve this with the class selectors which don't need to be unique.

    This also has a positive effect on speed because no complex search is required Additionally you can use this for the different styling of different elements

    e.g.

    element type aa
    element type aa
    element type aa and bb
    element type bb
    

    Now you can simply use the class selector

    $('.aa').click(function(){
         console.log( 'clicked type aa #' + $(this).attr('id') );
    });
    
    $('.bb').click(function(){
         console.log( 'clicked type bb #' + $(this).attr('id') );
    });
    

提交回复
热议问题