jQuery绑定动态创建的父元素的children元素

时间:2018-01-26 11:07:45

标签: javascript jquery element parent children

所以我很难处理动态创建的孩子的点击。

这是DOM:

font pango:monospace 8, FontAwesome 8

通过滚动创建整个<article id="randomly-generated-Id"> <div class="post-container"> <div class="post-view video-post"> <video preload="auto"> <source src="foo" type="video/mp4"> <source src="foo" type="video/webm"> </video> <div class="sound-toggle off"></div> <p class="length">0:43</p> <div class="presenting"><span class="play">Play</span></div> </div> </div </article>

我试图处理班级article

上的点击

到目前为止,这些都没有奏效:

sound-toggle

2 个答案:

答案 0 :(得分:0)

有效。查看this fiddle

您的HTML中缺少结束[XDebug] zend_extension = "C:\xampp\php\ext\php_xdebug.dll" xdebug.profiler_append = 0 xdebug.profiler_enable = 1 xdebug.profiler_enable_trigger = 0 xdebug.profiler_output_dir = "C:\xampp\tmp" xdebug.profiler_output_name = "cachegrind.out.%t-%s" xdebug.remote_enable = 1 xdebug.remote_autostart = 1 xdebug.remote_handler = "dbgp" xdebug.remote_host = "127.0.0.1" xdebug.remote_port = 9010 xdebug.auto_trace = 1 xdebug.trace_output_dir = "C:\xampp\trace" xdebug.idekey = "phpstorm" 标记,顺便说一句。就在结束div

之前

这是更新后的HTML

</article>

您无法在控制台中查看此问题的原因可能是您的<article id="randomly-generated-Id"> <div class="post-container"> <div class="post-view video-post"> <video preload="auto"> <source src="foo" type="video/mp4"> <source src="foo" type="video/webm"> </video> <div class="sound-toggle off"> </div> <p class="length">0:43</p> <div class="presenting"><span class="play">Play</span></div> </div> </div> </article> div没有采取任何高度或宽度。

答案 1 :(得分:0)

您的div标记未在</article>标记之前关闭。 顺便说一下,建议不要给文件绑定事件,因为可能会发生潜在的错误。 如果你理解我的意思,请反馈。感谢。

相关问题