JavaScript Triggers

JavaScript Triggers describes how you can use custom attributes to attach JavaScript events to elements.

It’s a good article and an interesting concept, but like several of the people commenting the article over at A List Apart, I’m not sure it’s worth the trouble of creating a custom DTD to be able to use custom attributes.

  • February 2, 2005
  • Comments closed
  • Posted in

Comments

1. February 2, 2005 by Woolly

Like the original poster on alistapart mentioned. ClassNames are a great (though) lesser alternative to bolt event handlers on. I've been playing with these for quite a while too. It keeps the source code nice and strict with all the event handling done externaly.

Imaging having this in you code:

<dt class="link classMouseHover toggleNextNode">
    click this to open definition 1
</dt>
<dd class="hideThisNode">
    Lorem ipsum dolor sit amet.
</dd>

Instead of all this:

<dt onclick="objNode0.style.display=
(objNode0.style.display=='none')?'block':'none';">
    click this to open definition 1
</dt>
<dd id="hidethis0">
    Lorem ipsum dolor sit amet.
</dd>
<script type="text/javascript">
    var objNode0 = document.getElementById('hidethis0');
    objNode0.style.display = 'none';
</script>

You might want a little look at my examples.

2. February 3, 2005 by Roger Johansson

Woolly: yes, that is a lot cleaner, and I've been using similar methods myself lately. I don't see myself going to the trouble of making a custom DTD though. Not at the moment, anyway.

Sorry, comments are closed for this post.

Information, sponsorship, and externals

Subscribe

SidebarAds

Looking for web hosting?

Try DreamHost!

Use the promo code 456BEREASTREET3 to save USD 20 when you sign up!

Favourites, here and elsewhere

Affiliation

  • NetRelations
  • Kaffesnobben
  • Dagens recept
  • 9rules network member

Support this site

Show your support by buying a book or two from SitePoint or getting me something from my Amazon Wish List.