![]() |
Using location.pathname to influence an image source.
Greetings,
I've started looking into Javascript to solve an issue on image replacements, however I've yet to grasp the concept of programming a tad more for the piece of code to work. On several webpages (Link) there's an image with the following HTML code: Code:
<img src="http://static.last.fm/flatness/catalogue/noimage/noalbum_g3.png" width="220" height="220" class="album-cover"/>Code:
var albumCover = document.getElementsByClassName('album-cover') // Get the album coverCode:
var albumCover = document.getElementsByClassName('album-cover') // Get the album coverCheers |
So you want to use the location.pathname stored in currentLink as a key to the "dictionary" object literal to retrieve the new image src?
Try this Code:
albumCover[0].src = dictionary[currentLink]; |
Thanks, that already helped a lot. However, if I may be so bold to ask for one small way of making the code a lot easier as the dictionary will grow bigger. Now my code is this:
Code:
var albumCover = document.getElementsByClassName('album-cover')[0] // Get the album coverIf not, no worries. This already got me what I needed. Cheers! |
But ahem ... this is exactly what I described in my previous post
Quote:
Code:
dictionary[location.pathname] |
There aren't enough facepalms in the universe to express the stupidity in my last post. Guess easy answers aren't meant for me.
That covered the problem, much appreciated. Cheers! |
| All times are GMT +1. The time now is 02:39 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.