Jquery + addClass +动态wordpress帖子id

时间:2012-12-17 19:05:37

标签: jquery html wordpress

我正在寻找有关向具有动态WordPress帖子ID的div添加类('Selected)的帮助。当点击链接时,它将跳转到具有WordPress帖子ID的相应div。我是否让Jquery找到锚链接到的动态div ID,并为其添加一个类?

HTML:

<a class="jump" href="#<?php the_ID(); ?>">
<div class="wrap">
<div class="content" style="width: ;">
 <div id="132" class="column">Post Div</div>
 <div id="345" class="column">Post Div</div>
 <div id="64" class="column">Post Div</div>
 <div id="22" class="column">Post Div</div>
</div>
</div>
</div>

Jquery的:

$('a.jump').click(function(){
$('#22').addClass('selected')
$(element).siblings().removeClass('selected')
});

1 个答案:

答案 0 :(得分:0)

$('a.jump').click(function(){

   // this.href will something like  #22, #132... etc

   $('div.content ' + this.href ).addClass('selected');
   $(element).siblings().removeClass('selected')
});