[thelist] .innerHTML help

Ken Kogler ken.kogler at curf.edu
Tue Sep 3 22:26:01 CDT 2002


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!");
    }

  }
-------------------------------------




More information about the thelist mailing list