zoldos
zoldos

Reputation: 45

how do I add a second variable to a simple javascript function?

This is part of a simple script that will produce a warning popup. Currently, it works for any links with a ":" as seen below. I'd like to add a second variable, so it will work for EITHER a ":" OR "#tabs-2".

$(function(){
$('a[href*=":"]').click(ask) // all links that have a colon in them.
})

Thanks!

Upvotes: 0

Views: 40

Answers (3)

Viswanath Donthi
Viswanath Donthi

Reputation: 1821

Use it as:

$('a[href*=":"], #tabs-2').click(ask);

Upvotes: 0

Mitya
Mitya

Reputation: 34556

First of all, you're not seeking to add a 'variable'; there's no variables at play here. What you're seeking to do is to widen your jQuery selector (a string) to match more elements than it currently does.

This is achieved by specifying the variants separated by commas:

$('a[href*=":"], #tabs-2') //<-- note comma

Beware, though: #tabs-2 sounds, to me, like a container, so you might actually mean something like

$('a[href*=":"], #tabs-2 a')

Upvotes: 3

Kiee
Kiee

Reputation: 10771

Just use a comma and specify another selector:

$(function(){
$('a[href*=":"], #tabs-2').click(ask) // all links that have a colon in them.
})

Upvotes: 2

Related Questions