Hi I'm trying to get Javascript to replace the first character of a div tag with a image (i.e. image of letter a if the first letter is a, image of letter b if the first letter is b etc.) and then replace the first text with the same text less the first character.
however this script it just tells me an object is required (somewhere around the body tag), so i've no idea what the problem is!
Does anyone have any idea what I've done wrong?
Code:
<html>
<head>
<script type="text/javascript">
<!--
function SFLIR(id_name){
var divs=document.getElementsByTagName('div')
for (var i=0;i<divs.length;i++){
if( div[i].id.indexOf(id_name)===0 ) {
bg_letter = div[i].innerHTML.charAt(0);
if (bg_letter != "<") {
div[i].style.backgroundImage.src = "images\lettersets\"+bg_letter+".gif";
div[i].style.backgroundImage.alt = bg_letter;
inht = div[i].style.innerHTML;
div[i].style.innerHTML = inht.subscring(1);
}
}
}
}
->
</script>
</head>
<body onLoad="SFLIR('main')">
Shouldn't change<br/>
<div id="main">Should change</div><br/>
<div>Shouldn't change</div><br/>
</body></html>