Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  15] [ 6]  / answers: 1 / hits: 99457  / 13 Years ago, thu, may 19, 2011, 12:00:00

document.getElementById(...).setAttribute('style',... is not working in Internet Explorer 7.0. How can I make this work in Internet Explorer?



<!DOCTYPE html> 
<html lang=en>

<head>
<script type=text/javascript>
var myarray=new Array(3);
for (i=0; i <1000; i++){
myarray[i]=new Array(3);
}
myarray[0][0]=new; myarray[0][1]=old;

function swapText(id){
document.getElementById('id' + id).setAttribute('style', 'font-weight: bold; color: red; font-size:150%;');
document.getElementById('id'+ id).innerHTML = myarray[id][0];
}
function originalText(id){
document.getElementById('id' + id).setAttribute('style', 'color:' + 'black' + ';');
document.getElementById('id' + id).innerHTML = myarray[id][1];
}
</script>
</head>
<body>
<div id=scoreboard border='1'> </div>
<div id=qa>
<div id=col1 class=column>
<div id=id0 onmouseover=swapText(0); onmouseout=originalText(0)>old</div>
</div>
</div>
</body>
</html>

More From » javascript

 Answers
34

Using setAttribute is unreliable if you want the change to be reflected in the document. Use Element.style instead:



var el = document.getElementById('id' + id);
el.style.fontWeight = 'bold';
el.style.color = 'red';
el.style.fontSize = '150%';


and suchlike.


[#92146] Wednesday, May 18, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jack

Total Points: 557
Total Questions: 96
Total Answers: 80

Location: Saint Helena
Member since Mon, Jan 16, 2023
1 Year ago
;