Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
访问动态泛型元素jquery的子元素_Jquery_Dom_Children - Fatal编程技术网

访问动态泛型元素jquery的子元素

访问动态泛型元素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

我有以下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'>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