你的問題似乎已經解決了(放錯地方的括號),但有一些方法可以選擇除了使用id
子元素。
<div id="homeDiv">
<div class="item" id="home1">home 1 text here</div>
<div class="item" id="home2">home 2 text here</div>
<div class="item" id="home3">home 3 text here</div>
<div class="item" id="home4">home 4 text here</div>
</div>
JS:
$("#homeDiv .item"); //If they are wrapped in a div, specify that and use descendant selection
<div class="item home" id="home1">home 1 text here</div>
<div class="item home" id="home2">home 2 text here</div>
<div class="item home" id="home3">home 3 text here</div>
<div class="item home" id="home4">home 4 text here</div>
JS:
$("div.item.home"); //Elements can have multiple classes
$(".home"); //And you can use any class name to select them.
更合適的方法是使用類名。你爲什麼厭惡課? –
該類名在應用程序的其他地方用於計算更大的div組,但不是所有的div。 – oshirowanen
元素可以有多個類'