我正在使用 $.get 函数加载局部 View :
$.get('/desk/nextstep', function (data) {
var ids = $(data).filter(':first').attr('id');
alert(ids);
});
我想获取第一个(根)div 的 id
,但这段代码不起作用:
var ids = $(data).filter(':first').attr('id');
我收到 undefined
警报消息。如何解决?
谢谢。
更新:
在 data
html 代码中:
<div id="step1" class="scroll-pane">
<div class="scroll_cont">
//other content
</div>
</div>
最佳答案
试试这个:
$.get('/desk/nextstep', function (data) {
var ids = $('<div/>').append(data).find(':first').attr('id');
alert(ids);
});
关于javascript - 获取通过ajax加载的页面中第一个div的id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11536896/