jquery 目标 html5 标记属性
我尝试使用 jQuery 简单地添加一个 .alt
类来替换主 section
中的 article
块,如下所示:
html5:
<section id="content" role="main">
<h1>Main Title</h1>
<article id="post-1" class="post-1 post type-post">
.. article content ..
</article>
<article id="post-2" class="post-2 post type-post">
.. article content ..
</article>
<article id="post-3" class="post-3 post type-post">
.. article content ..
</article>
</section>
jQuery:
$('#content article:nth-child(odd)').addClass('alt');
我是不是错过了什么……?这当然应该有效吗?
I'm trying to use jQuery to simply add an .alt
class to alternate article
blocks within a main section
as follows:
html5:
<section id="content" role="main">
<h1>Main Title</h1>
<article id="post-1" class="post-1 post type-post">
.. article content ..
</article>
<article id="post-2" class="post-2 post type-post">
.. article content ..
</article>
<article id="post-3" class="post-3 post type-post">
.. article content ..
</article>
</section>
jQuery:
$('#content article:nth-child(odd)').addClass('alt');
Am I missing something...? Surely this should work?!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上面的代码确实有效,我的 jQuery 文件中的其他内容抛出了问题。请参阅上面的评论。
The above code does work, other content in my jQuery file was throwing out problems. See the comments above.