LoginSignup
125
131

More than 5 years have passed since last update.

jQueryでclassやidをワイルドカード指定

Last updated at Posted at 2014-03-25

jQueryでワイルドカード指定取得方法、忘れがちなのでメモ。

<ul>
<li id="aaa1">TEST1</li>
<li id="aaa2">TEST2</li>
<li id="aaa3">TEST3</li>
</ul>
$(function(){
    $("[id^=aaa]").on("click",function(){
        console.log($(this).attr("id"));
    });
});

これのワイルドカード部分、id="aaa1"であれば「1」をclickイベント内で取りたい。
replace()で置換すれば良いんだろうけど、何かもっと簡単な方法があれば賢い人教えて~。

125
131
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
125
131