Use jQuery to grab the absolute path of a relative image

Good old jQuery has a function for everything it seems.  I was trying to obtain the absolute source path of an image which was linked relatively (eg: ‘/imgs/godsavethequeen.png’) but jQuery gives you just that – the relative path.

Sure you could do some trickery to grab the URL and append it together to create the absolute path, but seeing as I was using jQuery I thought I’d just take a look through their API to see if they had anything to fill my need.

Introducing jQuery’s ‘Prop‘ function.  Try something like this: $(‘img’).prop(‘src’) and watch jQuery wave its magic wand and give you the absolute path.

Feel free to add your comment..

Your email address will not be published.