我有一系列的照片頁面上,其中有他們下面一些文字資料和一些按鈕內確定一個特定的類元素:另一個DIV
<div class="photowrapper">
<div class="photowrapperphoto">
<div class="photocontainer">image</div>
</div>
<div class="textwrapperphoto">
<div class="textleftwrapperphoto">
<div class="phototitle">photo_0001</div>
<div class="photoprice">£3.00</div>
<div class="photosize">6 by 4 inch</div>
</div>
<div class="textrightwrapperphoto">
<div class="photoaddbutton">Add</div>
<div class="photoremovebutton">Delete</div>
</div>
</div>
我希望把一些jQuery的,這樣,當有人點擊'photoaddbutton',它修改'photowrapperphoto'類(添加背景顏色)。
我似乎無法弄清楚如何識別元素photowrapperphoto。
我在頁面上加載了上面的html(即圖片加載)。我只是想立即在之前的'photowrapperphoto'改變,但目前我正在使用的jQuery更改頁面上的所有'photowrapperphoto'類。
$(document).ready(function() {
$('.photoaddbutton').click(function() {
$('.photowrapperphoto').attr('class', 'photowrapperphotoselected');
});
});
任何想法?
我建議熟悉jQuery的[DOM遍歷方法](http://api.jquery.com/category/traversing/tree-traversal/)。 – tcovo