[英]get appended div id in jQuery
Is there any way I can get the id (or any other reference to) the element I've just appended using jQuery .append()
? 有什么方法可以获取我刚刚使用jQuery .append()
追加的元素的ID(或任何其他引用.append()
?
I'm receiving an html string with ajax and injecting in a div. 我收到带有ajax的html字符串并注入div。
$.get(URL, args).success(function (response) {
$('#mainDiv').append(response);
});
Now I have to change something to the newly appended div (like a css property). 现在,我必须对新添加的div进行更改(例如css属性)。
Please note! 请注意! These solutions are not accepted, reasons are provided. 不提供这些解决方案,但提供了原因。
Perhaps anybody know a secure, reliable and consistent way to access the node I've just created in mainDiv. 也许有人知道一种安全,可靠和一致的方式来访问我刚刚在mainDiv中创建的节点。 If .append always attach at the end, perhaps refering last node is ok: am I wrong? 如果.append总是附加在末尾,则可能引用最后一个节点是可以的:我错了吗?
You can have jQuery object reference like: var j =$(response);
您可以使用jQuery对象参考,例如: var j =$(response);
, and then append it : $('#mainDiv').append(j);
,然后附加: $('#mainDiv').append(j);
and change its css: j.css("border":"0");
并更改其CSS: j.css("border":"0");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.