<div class="gridmasonry grid_accomodation select_room">
<div class="item_grid item2">
<div class="panel">
<div class="img_preview">
<h4 class="price"><span>€20 </span>Night</h4>
<img src="~/Images/rooms/standard.jpg" alt="img_preview" />
</div>
<div class="clsRoomType"><h4>Standart Room</h4></div>
</div>
</div>
<div class="item_grid item2">
<div class="panel">
<div class="img_preview">
<h4 class="price"><span>€20 </span>Night</h4>
<img src="~/Images/rooms/luxury.jpg" alt="img_preview" />
</div>
<div class="clsRoomType"><h4>Luxury Room</h4></div>
</div>
</div>
<div class="item_grid item2">
<div class="panel">
<div class="img_preview">
<h4 class="price"><span>€20 </span>Night</h4>
<img src="~/Images/rooms/family.jpg" alt="img_preview"/>
</div>
<div class="clsRoomType"><h4>Family Room</h4></div>
</div>
</div>
<div class="item_grid item2">
<div class="panel">
<div class="img_preview">
<h4 class="price"><span>€20 </span>Night</h4>
<img src="~/Images/rooms/vip.jpg" alt="img_preview"/>
</div>
<div class="clsRoomType"><h4>VIP Room</h4></div>
</div>
</div>
<div class="item_grid item2">
<div class="panel">
<div class="img_preview">
<h4 class="price"><span>€20 </span>Night</h4>
<img src="~/Images/rooms/deluxe.jpg" alt="img_preview"/>
</div>
<div class="clsRoomType"><h4>Deluxe Room</h4></div>
</div>
</div>
<div class="item_grid item2">
<div class="panel">
<div class="img_preview">
<h4 class="price"><span>€20 </span>Night</h4>
<img src="~/Images/rooms/romantic.jpg" alt="img_preview" />
</div>
<div class="clsRoomType"><h4>Romantic Room</h4></div>
</div>
</div>
</div>
我有如上所述的DIV结构。当我单击带有“ item_grid item2”类的DIV项目时,每次需要获得带有“ clsRoomType”类的DIV文本。
我尝试了以下代码,但它显示了所有项目的文本
$(document).ready(function () {
$(".item2").click(function () {
alert($(".item2").find('div.clsRoomType').text());
});
});
当前结果:标准房豪华房家庭房贵宾房...
我想要每次点击的每个项目。
最佳答案
更换
alert($(".item2").find('div.clsRoomType').text());
与
alert($(this).find('div.clsRoomType').text());
那将给个别项目。
希望这可以帮助。