2011-06-15 85 views
0

我试图使用jQuery简单地添加一个.alt类交替内的主sectionarticle块如下:jquery的目标HTML5标记属性

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'); 

我错过了什么......?当然这应该工作?!

+0

它看起来像它对我有用 - http://jsfiddle.net/interdream/EBWPq/ – 2011-06-15 14:43:32

+0

XO你说得对,它是我的jquery文件中的其他内容阻止它!谢谢,我正在拉我的头发! – 2011-06-15 14:49:17

+0

@Jonny Wood - 请将您的评论回复并标记为已接受。 – cdeszaq 2011-09-16 16:31:34

回答

0

上面的代码确实有效,我的jQuery文件中的其他内容正在抛出问题。见上面的评论。