View Single Post
Old 01-26-2013, 03:14 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Do you *MEAN* turn off? In that case, instead of just changing the 0 to "" wouldn't you want to change the div's style to "display: none;"??

BUt anyway:
Code:
var divs = document.getElementsByTagname("div");
for ( var d = 0; d < divs.length; ++d )
{
    var div = divs[d];
    if ( div.innerHTML == "0" ) 
    {
        div.innerHTML = "";
        // or 
        div.style.display = "none";
    }
}
Note that this will process *ALL* the <div>s on your page.

If possible try to somehow "contain" them.

Example:
Code:
<div id="onlyLookHere">
    <div>8</div>
    <div>5</div>
    <div>0</div>
    <div>6</div>
    <div>0</div>
    <div>0</div>
    <div>1</div>
</div>
and then do:
Code:
var divs = document.getElementById("onlyLookHere").getElementsByTagname("div");
for ( var d = 0; d < divs.length; ++d )
{
    var div = divs[d];
    if ( div.innerHTML == "0" ) 
    {
        div.innerHTML = "";
        // or 
        div.style.display = "none";
    }
}
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
juliushg (01-26-2013)