In jQuery, when selecting by attribute value, why do we need to enclose the value in quotes '
'
?
$("#demo-dropdown a").click(function() {
var href = $(this).attr("href");
console.log(typeof (href)); // there shows `string`
$("#tab-list li a[href= '" + href + "']" ).tab("show"); // why the single-quotes?
});
If I use:
$("#tab-list li a[href=" + href + "]" ).tab("show");
then I will get a Syntax Error
:
Uncaught Error: Syntax error, unrecognized expression: #tab-list li a[href= #profile]
at Function.fa.error (jquery.min.js:2)
at fa.tokenize (jquery.min.js:2)
at fa.select (jquery.min.js:2)
at Function.fa [as find] (jquery.min.js:2)
at n.fn.init.find (jquery.min.js:2)
at new n.fn.init (jquery.min.js:2)
at n (jquery.min.js:2)
at HTMLAnchorElement.<anonymous> (index.html?_ijt=o70cto8b6ocd3tq2oh8bck1k4e:171)
at HTMLAnchorElement.dispatch (jquery.min.js:3)
at HTMLAnchorElement.r.handle (jquery.min.js:3)