How do I trigger a single event defined for a class of objects

Posted by mrbinky3000 on Stack Overflow See other posts from Stack Overflow or by mrbinky3000
Published on 2010-12-30T02:52:49Z Indexed on 2010/12/30 5:54 UTC
Read the original article Hit count: 231

Filed under:
|

I have a question. I have 8 buttons that have unique incrementing id's and a shared class.

<button class="btnChapter" id="btnChapter_1" value="1">1</button>
<button class="btnChapter" id="btnChapter_2" value="2">2</button>
<button class="btnChapter" id="btnChapter_3" value="3">3</button>
...

In order to prevent me from duplicating code, I bound a click event to the btnChapter class instead of binding an event individually to each button's ID.

$('.btnChapter').click(function(){ .. do stuff .. });

How do I trigger() the click() event only for #btnChapter_2? The following doesn't seem to work.

$('#btnChapter_2').click()

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery