akd
akd

Reputation: 6758

Selecting an element with dynamic href value?

I am trying to select an element as below

 $('a[href^="#Images_Tab"]')

This works fine however what actually need is this that the value of href is dynamic and I need to change the statement something like below;

$('a[href^="+hrefVal+"]')

I know this statement wrong as I have already tried it.

Any suggestion?

Upvotes: 2

Views: 54

Answers (2)

blackmind
blackmind

Reputation: 1296

You aren't closing your string prior to concatination, you need to do something like

$('a[href^="'+hrefVal+'"]')

Upvotes: 0

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Use single quotes instead of double quotes,

Try,

$('a[href^="' + hrefVal + '"]')

Upvotes: 2

Related Questions