View Full Version : action markers in html
09-27-2004, 03:49 AM
What's the word on placing meaningless event handlers wherever in the markup, just to tell your script what to do with the DOM? Say, for instance, that you want to go:
<element onclick="'do me'">content</element>
...and then onload, the script would iterate some element.collection, and check each onclick attribute for a "do me" string, act upon those, then, finally, either remove the onclick, or insert an actual action into it.
It works, but then, so do invalid attributes (as long as document.expando is enabled); can there be such a thing as invalid values for event handlers?
09-27-2004, 08:57 PM
So I gather that anything goes; that's nice (validity is cool). :D
09-27-2004, 09:18 PM
You mean adding useless elements to HTML just for the purpose of your script? Well, does it validate through the w3 when you do this? I would say you should do as much as you can to keep your HTML semantic and clean, but if you need to and it validates, well than so be it:)
09-27-2004, 10:12 PM
Yes, it validates.
I'm not sure about the semantics and all, but that's probably a gray area, being that a script can mean anything we want it to. :)
09-27-2004, 11:48 PM
Perhaps if you told us what you were up to, we'd be able to suggest a better method?
09-28-2004, 12:42 AM
I'm up to thinking theoretically ;)
But for a quick/basic example:
what if I wanted put various elements into a functional group?
A name attribute would be perfect, but that is invalid, so I'll just make my own. :D
<!-- saved from url=(0013)about:internet -->
window.onload = function()
var elements = document.body.getElementsByTagName("*");
for(var i = 0; i < elements.length; i++)
if(typeof elements[i].onmouseout == "function" && elements[i].onmouseout() == "foo")
elements[i].innerHTML = "namespace:foo";
<div onmouseout="return 'foo'">content...</div>
<span onmouseout="return 'foo'">content...</span>
Now, that's not really anything special by itself, but script defined grouping is potentially very useful.
By the way, that example would fire an onmouseout event for every element, so a comparison by regular expression, rather than return value, would be better... the idea remains the same, however.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.