Assuming I insert anything in my DOM with jQuery, like so:
$('#someselector').prepend('<img src="/img/myimage.gif" id="someid" />');
Is there a way in jQuery to get a jQuery
object referencing this new image, without having to do an extra search like
var myImage = $('#someselector #someid');
???
Make it into an jQuery object before prepending it:
var $img = $('<img src="/img/myimage.gif" id="someid" />');
$('#someselector').prepend($img);
$img.foo();
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