![](/img/trans.png)
[英]How do I get jQuery to select elements with a . (period) in their ID?
[英]JQuery: How do I get a DID ID?
我有以下HTML:
<div class="house">...</div>
但是在我的代碼中,我動態地插入了DIV ID以使代碼看起來像這樣:
<div class="house" id="id_1">...</div>
問題 :如何僅通過使用JQuery知道CLASS來獲得DIV ID? 我已經嘗試過類似以下的方法,但是它不起作用。
$('.house').getID();
$('div.house')
.each(function(index) {
alert( 'id for this div.class #'+index+': '+$(this).attr('id') );
});
我相信
$('.house').attr("id");
應該管用。 我沒有測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.