Larson B Larson B - 7 months ago 28
Javascript Question

Jquery attribute selector using string concatenation in version 1.12.1

I want to use a variable as a selector attribute.

This is how I used to do this.

var variable = 'string';
$('[href=#'+variable+']'); => $('href=#string')

But in jquery version 1.12.1, this is no longer supported.

So how would I refactor this without making it look too ugly?


Just add quotes around the internal link and it should work.

$('[href="#'+variable+'"]'); => $('href="#string"')