Reputation: 1678
I am developing a small lightbox wordpress plugin in which if a user clicks an image the image should appear in the lightbox. How can i identify URL of the image in which the user clicks, so it will be useful in showing the image in lightbox. Is this can be done in jquery? Can anyone help?
Upvotes: 1
Views: 1155
Reputation: 6192
You can do like this
$("img").click(function() {
var img_path = $(this).attr('src');
})
EDIT
change
data: dataString,
to
data: 'img_path='+img_path,
and you will be able to access the image path in lightbox.php like this
$image_path = $_POST['image_path'];
Upvotes: 4
Reputation: 140
Getting the image url is easy.
$(function() {
$('img').on('click', function( event ) {
var source = this.src;
console.log( source );
});
});
Upvotes: 1