Larson B Larson B - 1 year ago 113
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?

Answer Source

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

$('[href="#'+variable+'"]'); => $('href="#string"')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download