0

How can I pass multiple variables on a jquery function? Like so:

$(".link1",".link2").click(function(event){

}

Also tried:

$(".link1"),$(".link2").click(function(event){

}
Cobra_Fast
  • 14,992
  • 8
  • 56
  • 101
Tasos
  • 1,572
  • 4
  • 27
  • 45

3 Answers3

6

Use

$(".link1, .link2").click(function(event){

or

$(".link1").add(".link2").click(function(event){

The comma separator is defined here : Multiple selector

Denys Séguret
  • 355,860
  • 83
  • 755
  • 726
2

Multiple selectors need only be separated by a comma in your selector string.

$(".link1, .link2").click(function(event){

}
pete
  • 22,903
  • 4
  • 35
  • 51
1

use .on, and pass the extra events as an argument to that method:

$('.link1, link2').on('click',{some:'argument'},function(e)
{
    console.log(e.data);//<-- object literal {some:'arguments'}
});

Read all about it here

Elias Van Ootegem
  • 70,983
  • 9
  • 108
  • 145