访问动态泛型元素jquery的子元素
我有以下html,我想在类“tobook”的div元素的click事件中访问h6元素的“ABC”。此代码是在某个控制器的事件上动态生成的 如何做到这一点?提前谢谢访问动态泛型元素jquery的子元素,jquery,dom,children,Jquery,Dom,Children,我有以下html,我想在类“tobook”的div元素的click事件中访问h6元素的“ABC”。此代码是在某个控制器的事件上动态生成的 如何做到这一点?提前谢谢 <div class='shortcut-tiles seatdata tiles-success tobook'> <div class='tiles-body seatmap'> <span style='display:none' class='type'>S
<div class='shortcut-tiles seatdata tiles-success tobook'>
<div class='tiles-body seatmap'>
<span style='display:none' class='type'>Sleeper</span>
<span style='display:none' class='seatid'> 302</span>
<a href='#' >
<center>
<h6 data-type='text' data-title='E' class='sno' style='color:white font-size:14px !important;'>
ABC</h6>
</center>
</a>
</div>
</div>
卧铺
302
试试这个
$(document).on('click', '.tobook', function () {
var text = $(this).closest('.tobook').find('h6.sno').text();
alert(text);
});
对于它的价值,
中心
被折旧;您不应该使用它来集中内容。您会像访问其他元素一样访问该元素吗?你将不得不等到它出现,因为你无法访问文本a future element。感谢JoshC和Adeneo的指导。谢谢,伙计,这对我有用。我没有尝试$(这个),而是使用children()api