开发者

Combining Variables

开发者 https://www.devze.com 2023-03-21 16:06 出处:网络
I have a function: function prodSubSection(div, sec, self) { $(\".prod-feat\").hide(); $(div + sec).show(\'slide\', {direction: \'right\'}, 1000);

I have a function:

function prodSubSection(div, sec, self) {
   $(".prod-feat").hide();
   $(div + sec).show('slide', {direction: 'right'}, 1000);
   $(self)
     .addClass('prodDetailsOn')
     .parent('li').siblings().find("a")
     .removeClass('prodDetailsOn');
}

And here is how I execute it:

$("#product1 li.details1 a").click(function() {
   prodSubSection("#product1", ".over", this);
   return false;
});

开发者_运维百科What I would like is to combine div and sec so above would be:

$("#product1 .over").show('slide', {direction: 'right'}, 1000);

Any idea what I am doing wrong?


I think you just need a space between div + sec... so div + " " + sec.

Without the space, you will be looking for #product1.over, so an element named product1 AND has a class of over, instead of all elements with a class of over INSIDE of an element with the name of product1.


Add a space:

$(div + ' ' + sec)
0

精彩评论

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