如何使用 jQuery 检索此 ID?
<span data-itemkey="40e1eec6-f949-468e-8a25-ba97d0ec3fb2" class="word">
<div class="additionalStyling green" id="2">Approval Process</div>
</span>
我尝试了这个,它返回未定义
$(document).on("click", ".word", function (e) {
var id = $(".word:first-child").attr("id");
}
最佳答案
更改此:
var id = $(".word:first-child").attr("id");
致:
var id = $(this).find("> div").first().attr("id");
只是为了确保,我没有复制相同的内容:
var id = $(this).children().first().attr('id');
关于javascript - 使用 jQuery 获取 child id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34266163/