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?
2 Answers
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'];
6 Comments
sun
is there any way to pass this img_path value to php variable?
Nauphal
@raj: how about using
ajax ?sun
$("img").click(function() { var img_path = $(this).attr('src'); $.ajax({ type:'POST', url: 'lightbox.php', dataType: 'HTML', data: dataString, success: function(data){ } }); });this is the ajax i tried but cant get itsun
Ya i tried but not working. Is there any changes to be made on
success: function(data){ }sun
is it possible to append this
img_path to img tag like this <img src"value of img_path here"> |