sun
sun

Reputation: 1678

How to get the URL of the image using jquery in wordpress?

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

Answers (2)

Nauphal
Nauphal

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

stefan
stefan

Reputation: 140

Getting the image url is easy.

$(function() {

  $('img').on('click', function( event ) {
    var source = this.src;    
    console.log( source );
  });

});

Upvotes: 1

Related Questions