我正在寻找有关向具有动态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')
});
答案 0 :(得分:0)
$('a.jump').click(function(){
// this.href will something like #22, #132... etc
$('div.content ' + this.href ).addClass('selected');
$(element).siblings().removeClass('selected')
});