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
  • 15,671
  • 8
  • 57
  • 102
Tasos
  • 1,622
  • 4
  • 28
  • 47

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
  • 372,613
  • 87
  • 782
  • 758
2

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

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

}
pete
  • 24,141
  • 4
  • 37
  • 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
  • 74,482
  • 9
  • 111
  • 149