如何在类'album_revieuws'的部分中将类添加到奇数类“recensie”

时间:2014-06-18 11:48:24

标签: jquery

所以我有这个问题。

我想知道如何添加课程"选择" 在仅使用类album_reviews的部分中,对于称为recensie的每个奇数类。

<section class="album_reviews">
    <h2 class="sectiontitel"> Album Reviews </h2>
    <article class="recensie">
      <h1> Neil Young – A Letter Home </h1>
      <img src="Images/Albums/A_Letter_Home.jpg" alt="album_image"/>
      <p>Earlier this year, Neil Young unveiled Pono, a super-high-def audio service meant to deliver us from the sonic crimes of the earbud era. For his next act, he's released an acoustic covers set recorded at Jack White's Nashville music shop on a Voice-O-Graph--a super-low-def 1940s contraption that looks like a phone booth and sounds a few steps removed from a rusty tin can and some twine. If it's meant as some kind of joke, here's the punch line: In its perverse way, A Letter Home is one of the most enjoyable records Young has made this century.</p>
      <p> 
        <a href="http://www.rollingstone.com/music/albumreviews/a-letter-home-20140502#ixzz33g0Hq3pw"> Read more </a>
      </p>       
    </article>
  </section>

  <section class="band_members">
    <h2 class="sectiontitel"> Band Members</h2>
    <article class="recensie">
      <h1> Neil Young </h1>
      <figure>
          <img src="Images/Artists/Neil_Young.jpg" alt="Macaque in the trees">
          <figcaption> Neil Young <br /> Singer Songwriter </figcaption>
      </figure>
    </article>
  </section>

那是我的HTML代码。 我知道如何只将类添加到奇数中但不仅仅是在section中的几率.album_reviews

希望有人可以提供帮助

3 个答案:

答案 0 :(得分:1)

像这样:

$('.album_reviews .recensie:odd').addClass('selected');

答案 1 :(得分:0)

在jquery中使用:odd选择器。它选择所有奇数元素

$("section.album_reviews .recensie:odd").addClass('selected');

答案 2 :(得分:0)

$('.album_reviews').find('.recensie:odd').addClass('selected');

DEMO