[英]Dynamic clicked button - access dynamic content
I have a button thumb
that is created later (not exist when document load),我有一个稍后创建的按钮thumb
(文档加载时不存在),
$(document).on('click', '.thumb', function(){
console.log("clicked",$(".productPhoto"),$(this).attr("src"));
The issue is that productPhoto
is also being created later, and although i can click the thumb , if i try to print productPhoto
, i get nothing, but the element is there when i click.问题是稍后还会创建productPhoto
,虽然我可以单击 thumb ,但如果我尝试打印productPhoto
,我什么也得不到,但是当我单击时元素就在那里。
Is there a way to access also an element that is being created later (on click)?有没有办法访问稍后创建的元素(点击时)? ( without registering it for click on creation) (无需注册即可点击创建)
try calling dynamic elements using parent static elements as prefix eg: $("#div1.foo")
尝试使用父 static 元素作为前缀调用动态元素,例如: $("#div1.foo")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.