Wildcards in jQuery selectors

前端 未结 6 2460
逝去的感伤
逝去的感伤 2020-11-22 06:18

I\'m trying to use a wildcard to get the id of all the elements whose id begin with \"jander\". I tried $(\'#jander*\'), $(\'#jander%\') but it doe

6条回答
  •  时光取名叫无心
    2020-11-22 07:01

    To get the id from the wildcard match:

    $('[id^=pick_]').click(
      function(event) {
    
        // Do something with the id # here: 
        alert('Picked: '+ event.target.id.slice(5));
    
      }
    );
    
    
    moo1
    moo2
    moo3

提交回复
热议问题