0

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!

3 Answers 3

3

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')
Sign up to request clarification or add additional context in comments.

3 Comments

This actually breaks the script. Well the other one, I'm using a loading page script. It's okay tho, as I don't think it would produce the effect I wanted anyway....
Well, I can't know what your script environment is. But my answer contains no errors, and answered the question as you initially phrased it.
Agreed, and I appreciate it. :)
2

Just use a comma and specify another selector:

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

Comments

0

Use it as:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.