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?

Related posts

Leave a Reply

2 comments

  1. 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'];
    
  2. Getting the image url is easy.

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