I used JavaScript to modify some style on the page and then alert the modified style. In IE v7, though t开发者_JAVA百科he alerted message shows that the change has been made, visual rendering of the page shows no difference. The same code however works fine in FF. What could the reason be? Another thing i noted is when i used a developer toolbar's script console I was able to get the expected results but not when i put the js in a script tag.
Sample Code -
function change()
{
var text=document.getElementsByTagName("h2");
var i=0;
var p=text[0];
while(p)
{
alert(p.style.cssText);
p.style.cssText="color:#565656;";
p.innerHTML="Changed";
alert(p.parentNode.innerHTML);
i++;
p=text[i];
}
}
This was simply put in a script tag and put inside body just to test. The change made to innerHTML or style is not reflected in IE browser window though the later JavaScript alert shows the change.
Instead of changing the style that way, directly set the "color" property:
p.style.color = '#565656';
精彩评论