I am trying to add a text line to an image without an id or a class I have a series of images such as
<img src="../img/star.png" /><span>no text here until left img is clicked</span>
<img src="../img/someotherpicture.png" /><span>no text here until left img is clicked</span>
<img src="../img/anotherpicture.png" /><span>no text here until left img is clicked</span>
and for jquery i have
$(document).ready(function(){
$("img").click(function(){
$("img").next.$("span").val("info inserted after clicking on the img next to spa");
})
});
I’m a little bit confused as to how i should use next here, or maybe i should use find? I always have an img followed by a span.
Your selectors and methods are incorrect. In order to target the span, use:
Then, to change the text inside a node, use
.text()instead of.val():(.val() is used for input fields).