I have a ul
which contains images. These images are profile images fetched from twitter and appended into the ul
dynamically. 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. 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 ()"]
Could you please help me understand what I am doing wrong? Thanks for reading!
nextSibling returns the next node (an element node, a text node or a comment node). Whitespace between elements are also text nodes. nextElementSibling returns the next element (not text and comment nodes).
jQuery next() Method The next() method returns the next sibling element of the selected element. Sibling elements are elements that share the same parent. The DOM tree: This method traverse forward along the next sibling of DOM elements.
Nothing wrong.
That is how Chrome now logs jQuery objects.
Now go have some fun with it!
Try:
$("ul#container").on("click", "img", function(){
var nextImage = $(this).next().get(0);
console.log(nextImage);
}
Or
Try This Plugin For Chrome
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With