[英]Selecting the next sibling of the item just clicked
I have a ul
which contains images. 我有一个包含图像的ul
。 These images are profile images fetched from twitter and appended into the ul
dynamically. 这些图像是从twitter获取的配置文件图像并动态附加到ul
。 Once the user clicks on any of the images, I need to also cache the node of the image right next to it (the next sibling). 一旦用户点击任何图像,我还需要将图像的节点缓存在它旁边(下一个兄弟)。 I tried using the next()
selector like below, but what gets logged in the console is a message I do not understand. 我尝试使用next()
选择器,如下所示,但在控制台中记录的是一条我不明白的消息。 Here is the code: 这是代码:
$("ul#container").on("click", "img", function(){
var nextImage = $(this).next();
console.log(nextImage);
}
Here is what gets logged in the console: 以下是在控制台中记录的内容:
[prevObject: p.fn.p.init[1], context: , selector: ".next ()"] [prevObject:p.fn.p.init [1],context :, selector:“。next()”]
Could you please help me understand what I am doing wrong? 你能帮我理解我做错了什么吗? Thanks for reading! 谢谢阅读!
Nothing wrong. 没有错。
That is how Chrome now logs jQuery objects. 这就是Chrome现在记录jQuery对象的方式。
Now go have some fun with it! 现在去玩吧!
Try: 尝试:
$("ul#container").on("click", "img", function(){
var nextImage = $(this).next().get(0);
console.log(nextImage);
}
Or 要么
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.