Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts

    action markers in html

    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?

    Just curious...
    *this message will self destruct in n-seconds*

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So I gather that anything goes; that's nice (validity is cool).
    *this message will self destruct in n-seconds*

  • #3
    Senior Coder
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    2,469
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think that's because most of us are 'what's this javascript' in this area We're not as good as the javascript guys, though liorean and many of the others can whoop me something good here.

    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
    // Art is what you can get away with. <-- Andy Warhol
    ...:.:::: bradyjfrey.com : htmldog : ::::.:...

  • #4
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks.

    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.
    *this message will self destruct in n-seconds*

  • #5
    Senior Coder
    Join Date
    Feb 2003
    Location
    Ontario, Canada
    Posts
    1,223
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perhaps if you told us what you were up to, we'd be able to suggest a better method?

  • #6
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Code:
    <!-- saved from url=(0013)about:internet -->
    <script type="text/javascript">
    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";
    }
    </script>
    <p>content...</p>
    <div onmouseout="return 'foo'">content...</div>
    <p>content...</p>
    <span onmouseout="return 'foo'">content...</span>
    <p>content...</p>
    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.
    Last edited by codegoboom; 09-28-2004 at 01:23 AM.
    *this message will self destruct in n-seconds*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •