I’m trying to select only the follwing img of a class using jQuery.
Shouldn’t this work:
$('.upload_preview').next('img').attr('src',imgurl);
This works perfectly fine and will populate all img tags, but I just need the immediate follwing one
$('.upload_preview img').attr('src',imgurl);
The problem I am having is there are multiple upload fields. Once I upload an image I need to grab that immediate img tag and populate it. This is going inside a click function using the WordPress Media Uploader.
Try this:
You stated that using
$('.upload_preview img')got all of your images, so from that set simply take the.first()one…Note that “immediate following image” is a misleading way to describe the image element if the image is inside the
'.upload_preview'element (which it must be for your second line of code to do what you say it does). “First child image” might be a better way to put it.