开发者

Why is this jQuery not working?

开发者 https://www.devze.com 2023-01-22 21:59 出处:网络
$(function () { var sr = \'section.row\'; var fot = \'figure.one_third\'; var pA = \'div.portfolio ul li a\';
$(function () {


   var sr = 'section.row';
   var fot = 'figure.one_third';
   var pA = 'div.portfolio ul li a'; 

 开发者_JS百科  var item = ('sr fot pA');

   $item.addClass('blue');

});

http://jsfiddle.net/G8yJj/13/ <<


the line needs to be:

var item = $(pA);
item.addClass('blue');

or in your updated question:

var item = $(sr + ' ' + fot + ' ' + pA);

if that's what you want.


There's no need for any extra quotes.

Just use var $item = $(pA);


sr and fot are not getting evaluated as variables, they are just part of the string.

You need

$(sr + "," + fot + "," + pA)


As cambraca said in a comment, no quotes.

$(function () {

   var pA = 'div.portfolio ul li a'; 

   var $item = $(pA);

   $item.addClass('blue');

});

You do write

   var $item = $("div.portfolio ul li a");

But thats only because you need to have a way to mark the selector div.portfolio ul li a as a non-javascript query. If you explicitly make a String with those contents, then quoting it would read like this.

   var $item = $('"' . '"div.portfolio ul li a"' .'"');

And, that doesn't make sense.

0

精彩评论

暂无评论...
验证码 换一张
取 消