我有一些<article>
带有类的标签,还有两个按钮根据它们的类显示和隐藏某些文章 - 但它不起作用
有两个按钮:.latestClick
和.mostViewedClick
。每个都应该显示自己相应的<article>
标签:<article>
带有类的标签.latest
应该在单击.latestClick
按钮时显示,按钮也是如此.mostViewedClick
。有些<article>
标签有机器人类,所以当点击两个按钮中的任何一个时,它应该会显示出来。
jQuery
$('#featuredToggle ul li a').click(function (e) {
e.preventDefault();
if ($(this).hasClass('latestClick')) {
$('article .mostViewed').toggleClass('hideArticle');
$('article .latest').toggleClass('showArticle');
} else if ($(this).hasClass('mostViewedClick')) {
$('article .latest').toggleClass('hideArticle');
$('article .mostViewed').toggleClass('showArticle');
}
});
HTML:
<div id="featuredToggle">
<ul>
<li><a class="latestClick" href="#">Latest</a>
</li>
<li><a class="mostViewedClick" href="#">Most Viewed</a>
</li>
</ul>
</div>
<div class="box_mini block feed">
<article class="latest"> <a href="post.html"><img src="img/175x175.jpg" alt="" /></a>
<div class="content">
<h4><a href="post.html">SUV's</a></h4>
</div>
</article>
<article class="mostViewed hideArticle"> <a href="post.html"><img src="img/175x175.jpg" alt="" /></a>
<div class="content">
<h4><a href="post.html">Bakkies</a></h4>
</div>
</article>
<article class="latest mostViewed"> <a href="post.html"><img src="img/175x175.jpg" alt="" /></a>
<div class="content">
<h4><a href="post.html">Hatch Back</a></h4>
</div>
</article>
<article class="latest mostViewed"> <a href="post.html"><img src="img/175x175.jpg" alt="" /></a>
<div class="content">
<h4><a href="post.html">Sedan</a></h4>
</div>
</article>
<article class="latest"> <a href="post.html"><img src="img/175x175.jpg" alt="" /></a>
<div class="content">
<h4><a href="post.html">Coupe</a></h4>
</div>
</article>
</div>
CSS:
.hideArticle {
display: none;
}
.showArticle {
display: block;
}
我在这里做错了什么?