[thelist] .innerHTML help

Aaron Boodman aaron at youngpup.net
Tue Sep 3 22:31:11 CDT 2002


one of the great things about javascript: expando properties.

   function censor() {
     var totalSpans = content.getElementsByTagName("span").length;
     spans = document.body.getElementsByTagName("span");
     if (document.styleForm.swearFilter.checked) {
       for (i=0;i<totalSpans;i++) {
         spans[i].oldInnerHTML = spans[i].innerHTML;
         spans[i].innerHTML = '*****'
       }
     } else {
       for (i=0;i<totalSpans;i++) {
         spans[i].innerHTML = spans[i].oldInnerHTML;
       }
     }

   }


-- Aaron Boodman aaron | www @ youngpup.net
----- Original Message -----
From: "Ken Kogler" <ken.kogler at curf.edu>
To: <thelist at lists.evolt.org>
Sent: Tuesday, September 03, 2002 8:25 PM
Subject: [thelist] .innerHTML help


> This is one of those because-I-can projects -- more like a proof of
> concept than anything else.
>
> Problem is, my javascript skills suck. :)
>
> I'm making a dirty-words-filter for my blog. I'm wrapping each "bad"
> word in a <span> tag, like this:
>
>   <span class="dirtyWord">dirty</span>
>
> I've got a checkbox that calls "censor()" when it is clicked. At this
> point, censor() rips through all the spans within a <TD> with the ID of
> "content", and uses the .innerHTML property to change the word "dirty"
> to "******"
>
> Stupid (at least for my site), but amusing... :)
>
> You can see this in action here (), but if swear words offend you, don't
> click it please. No flames about offensive material -- you've been
> warned.
>
> There's more things I'd like it to do, but I can't figure out how to do
> it:
>
> 1) Replace each letter with a "*" (4 letter words replaced by "****" and
> 6 letter words replaced by "******", etc...)
>
> 2) Revert the "******" back to the dirty words when the checkbox is
> unchecked.
>
> Any help is appreciated! Thanks in advance.
>
> --Ken
>
> Almost forgot... here's censor() :
>
> -------------------------------------
>   function censor() {
>     var totalSpans = content.getElementsByTagName("span").length;
>     spans = document.body.getElementsByTagName("span");
>     if (document.styleForm.swearFilter.checked) {
>       for (i=0;i<totalSpans;i++) {
>         spans[i].innerHTML = '*****'
>       }
>     } else {
>       alert("you just unchecked the box!");
>     }
>
>   }
> -------------------------------------
>
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of thelist go to:
> http://lists.evolt.org Workers of the Web, evolt !
>




More information about the thelist mailing list