Reputation: 1289
I need to pass a string AND a variable as a selector into a href attribute, but I can't seem to get the syntax correct. Can anybody help?
I currently have a variable 'gallery' which I need to pass in the something like:
$('#work_gallery li a[href="http://www.ddbremedy.co.uk/siteupdate/" + gallery + ]');
Upvotes: 0
Views: 88
Reputation: 94499
Switch the selector to use double quotes so you can use single quotes within the attribute selector.
$("#work_gallery li a[href='http://www.ddbremedy.co.uk/siteupdate/" + gallery + "']");
Unless you have multiple links to the same page the first part of the selector, #work_gallery li
may be unnecessary. If this link only appears once on the page use:
$("a[href='http://www.ddbremedy.co.uk/siteupdate/" + gallery + "']");
Working Example: http://jsfiddle.net/jFYGM/
Upvotes: 1
Reputation: 68616
Like so -
$('#work_gallery li a[href="http://www.ddbremedy.co.uk/siteupdate/' + gallery + '"]');
Upvotes: 1