Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
130
Help us understand the problem. What is going on with this article?

More than 5 years have passed since last update.

@miiitaka

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

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()で置換すれば良いんだろうけど、何かもっと簡単な方法があれば賢い人教えて~。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
130
Help us understand the problem. What is going on with this article?