C
Csaba Gabor
Are the browsers generally efficient about checking when
domElem.att=newVal does not require any work, or (?) is this something
that it makes sense to do in my javascript via
if (domElem.att!=newVal) domElem.att=newVal
For example,
elemIFrame.src = possiblyNewURL;
elemSelect.options[optionIndex].text = possiblyNewVal;
elem.style.display = possiblyToggleDisplay; // "" or "none"
elem.style.visibitility = possiblyToggle; // "visible" or "hidden"
elem.innerHTML = possiblyNewHTML;
If I just consider this last case and suppose that I have a div whose
innerHTML is <font color=red>foo</font> and then update the innerHTML
of the div to be the same thing, then the browser must replace the
element. To see this, consider the following script - though the
behaviour is different in FF vs. IE, in both cases, the <font...>
element is replaced as is demonstrated by the fact that clicking the
first time gets you different behaviour than clicking the second time.
<div id=mydiv><font color=red onclick="
var iH=this.parentNode.innerHTML;
alert(iH);
this.parentNode.innerHTML=iH">Click me</font></div>
<script type='text/javascript'>
var mydiv=document.getElementById('mydiv');
var myfont=mydiv.childNodes[0];
myfont.onclick=function() {
var iH=this.parentNode.innerHTML;
alert("next Time around you won't see this message\n\n"+iH);
this.parentNode.innerHTML=iH; }
</script>
But the question for me is: does the browser take time to redo the
display or does it realize that there is no change? Of course, there
may be certain event handlers monitoring whether the DOM has changed,
in which case the page must be recalculated. But suppose that all
properties/attributes (e.g. CSS settings) that could possibly affect
the display are the same.
The other cases I mentioned above are a bit simpler in nature, since
they don't change the DOM itself. Still, I am more interested in the
answers to them. Ultimately, I wonder if anyone has practical
experience or done any testing along these lines.
Regards,
Csaba Gabor from Vienna
domElem.att=newVal does not require any work, or (?) is this something
that it makes sense to do in my javascript via
if (domElem.att!=newVal) domElem.att=newVal
For example,
elemIFrame.src = possiblyNewURL;
elemSelect.options[optionIndex].text = possiblyNewVal;
elem.style.display = possiblyToggleDisplay; // "" or "none"
elem.style.visibitility = possiblyToggle; // "visible" or "hidden"
elem.innerHTML = possiblyNewHTML;
If I just consider this last case and suppose that I have a div whose
innerHTML is <font color=red>foo</font> and then update the innerHTML
of the div to be the same thing, then the browser must replace the
element. To see this, consider the following script - though the
behaviour is different in FF vs. IE, in both cases, the <font...>
element is replaced as is demonstrated by the fact that clicking the
first time gets you different behaviour than clicking the second time.
<div id=mydiv><font color=red onclick="
var iH=this.parentNode.innerHTML;
alert(iH);
this.parentNode.innerHTML=iH">Click me</font></div>
<script type='text/javascript'>
var mydiv=document.getElementById('mydiv');
var myfont=mydiv.childNodes[0];
myfont.onclick=function() {
var iH=this.parentNode.innerHTML;
alert("next Time around you won't see this message\n\n"+iH);
this.parentNode.innerHTML=iH; }
</script>
But the question for me is: does the browser take time to redo the
display or does it realize that there is no change? Of course, there
may be certain event handlers monitoring whether the DOM has changed,
in which case the page must be recalculated. But suppose that all
properties/attributes (e.g. CSS settings) that could possibly affect
the display are the same.
The other cases I mentioned above are a bit simpler in nature, since
they don't change the DOM itself. Still, I am more interested in the
answers to them. Ultimately, I wonder if anyone has practical
experience or done any testing along these lines.
Regards,
Csaba Gabor from Vienna