开发者

jquery manipulating multiple elements

开发者 https://www.devze.com 2023-01-04 20:06 出处:网络
I\'m trying to manipulate two elements within a jquery function and i\'m not seeing the light. I\'m开发者_如何学C using the following code which works well on showing the required div, but i would lik

I'm trying to manipulate two elements within a jquery function and i'm not seeing the light. I'm开发者_如何学C using the following code which works well on showing the required div, but i would like to add highlighting to a paragraph item in another part of the page as well?

$('.lang-click').click(function(event){
  $('.lang').hide();
  $("li").removeClass("lang-on");
  event.preventDefault();
  $(this).parent().addClass("lang-on");
  $($(this).attr('href')).fadeIn(500);     
 });

I have tried this - which does not work:

$('.lang-click').click(function(event){
  $('.lang').hide();
  $("li").removeClass("lang-on");
  event.preventDefault();
  $(this).parent().addClass("lang-on");
  $($(this).attr('href')).fadeIn(500);
  var href = $(this).attr('href');
  $($(this).attr('href', href + '-cont')).addClass("cont-on");
 });


$($(this).attr('href', href + '-cont')).addClass("cont-on");

Maybe this line is the problem?

$(this).attr('href', "something") 

returns the link element itself, not "something".

Is this, what you're trying to do?

$($(this).attr('href')+ '-cont').addClass("cont-on");
0

精彩评论

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