Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-30-2011, 07:29 AM   PM User | #1
andrew1234
Regular Coder

 
Join Date: Oct 2002
Posts: 147
Thanks: 31
Thanked 2 Times in 2 Posts
andrew1234 is an unknown quantity at this point
multiple ids to share one click event

Is there a way to assign multiple ids to share one click event?


Code:
//this is what i'm doing now - to much code
$("#button1").click(function(){
  alert('test');
});
$("#button2").click(function(){
  alert('test');
});
$("#button3").click(function(){
  alert('test');
});
$("#button3").click(function(){
  alert('test');
});
Code:
//is this possible
$("#button1"   or "#button2" or "#button3" or "#button4" ).click(function(){
  alert('test');
});
andrew1234 is offline   Reply With Quote
Old 10-30-2011, 08:41 AM   PM User | #2
SB65
Senior Coder

 
Join Date: Feb 2009
Location: West Yorkshire
Posts: 2,816
Thanks: 9
Thanked 681 Times in 675 Posts
SB65 will become famous soon enoughSB65 will become famous soon enough
Yes, separate your selectors with commas:

Code:
$("#button1,#button2,#button3,#button4" ).click(function(){
  alert('test');
});
SB65 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:06 AM.


Advertisement
Log in to turn off these ads.