[thelist] .innerHTML help

Ken Kogler ken.kogler at curf.edu
Wed Sep 4 12:21:02 CDT 2002


> Anyway, thanks for the inspiration Aaron.

*ahem* You're welcome. ;)

Aaron and Lindsay proved to be *very* helpful in adding the extra
functionality I was lacking, though. Thanks again -- you guys rock!

> Incidentally, I adapted the script so that it
> now identifies the swearwords based on a custom
> CSS Class rather than applying the script to
> every <span> tag on the page.

The original script only looks at the <span>s WITHIN <td id="content">.
I left out the .className check since I don't plan on using the <span>
tag in my blog posts for anything except the filter, but to add the
custom class functionality to it (for extra caution), you'd just have to
add a little if statement like this:

-------- OLD WAY --------
   function censor() {
     // free for use, but maintain credit.
     // written by Ken Kogler (kenkogler.com)
     // with some help from Aaron Boodman
     // (youngpup.net) and Lindsay Evans
     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 = spans[i].oldInnerHTML.replace(/./g, "*");
       }
     } else {
       for (i=0;i<totalSpans;i++) {
         spans[i].innerHTML = spans[i].oldInnerHTML;
       }
     }
   }
------- / OLD WAY --------

-------- NEW WAY --------
   function censor() {
     // free for use, but maintain credit.
     // written by Ken Kogler (kenkogler.com)
     // with some help from Aaron Boodman
     // (youngpup.net) and Lindsay Evans
     var totalSpans = content.getElementsByTagName("span").length;
     spans = document.body.getElementsByTagName("span");
     if (document.styleForm.swearFilter.checked) {
       for (i=0;i<totalSpans;i++) {
         if (spans[i].className = 'badWord') { // <-- ***NEW LINE***
           spans[i].oldInnerHTML = spans[i].innerHTML;
           spans[i].innerHTML = spans[i].oldInnerHTML.replace(/./g,
"*");
         }
       }
     } else {
       for (i=0;i<totalSpans;i++) {
         spans[i].innerHTML = spans[i].oldInnerHTML;
       }
     }
   }
------- / NEW WAY --------

Anyway, this little experiment was a rousing success -- thanks to all
who helped me out! Maybe I'll turn this into my first article for
evolt... Depends on how much homework I have this week! :)

--Ken Kogler




More information about the thelist mailing list