Reputation: 8274
I am trying this, but it isn't working:
$('.prod_images').on('click', 'img', function() {
var myElement = $(this);
var img = myElement.clone();
$('.imageprod').append(img);
});
$('.imageprod').on('click', 'img', function() {
var myElement = $(this);
var img = myElement.remove();
});
Basically .prod_images
is the class of the images being clicked on.. I have a modal that opens when clicked on using a simple jquery .show();
div. I would like the clicked on image's source to populate into the empty <img src="" class="imageprod">
that is marked-up within my modal.
Update: Essentially; I would like to update a specified image source via class selector, to update based on the specified image source clicked.
<img src="goose.jpg" class="clickme"><!-- image src one-->
When you click 'img .clickme
' a modal appears..
Within this modal there is an empty <img src="" class="empty">
I would like the img
that was initially clicked, for it's src
to populate the specified .empty
one in my modal that appears.
Upvotes: 3
Views: 82
Reputation: 781096
I'm not totally sure what you're doing, but maybe this is it:
$('.prod_images'.on('click', 'img.clickme', function() {
$('.empty').attr('src', this.src);
});
If you just want to copy the source from one element to another, you don't need to clone anything.
Upvotes: 1