View Single Post
Old 11-14-2012, 08:28 PM   PM User | #1
WhatABoringName
New to the CF scene

 
Join Date: Nov 2012
Posts: 5
Thanks: 2
Thanked 0 Times in 0 Posts
WhatABoringName is an unknown quantity at this point
indexOf() function with a variable string?

Greetings,

for the following webpage I created a piece of Javascript to fill in the missing images: Link

Code:
var imageGet = document.getElementsByClassName('art');
var i = imageGet.length;
var a;

while (--i>=0)
	{

	a = imageGet[i].parentNode.parentNode.getAttribute('href');


		if (a.indexOf('/Larks%27+Tongues+in+Aspic') > -1)
		{
		imageGet[i].src = 'http://i1325.photobucket.com/albums/u622/last_fm_projeKct/Last%20FM%20covers/64%20x%2064/ltia.jpg'
		};


		if (a.indexOf('/Three+of+a+Perfect+Pair') > -1)
		{
		imageGet[i].src = 'http://i1325.photobucket.com/albums/u622/last_fm_projeKct/Last%20FM%20covers/64%20x%2064/3oapp.jpg'
		};

	};
While this actually does what is supposed to happen, I was wondering if there's a neater way of including more possible strings for the indexOf()-function, without making a new 'if'-statement for every piece of string I'd want to include eventually.

Thanks for taking the time to read this.

Cheers!
WhatABoringName is offline   Reply With Quote