Set onBlur() programmatically?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Thompson

    #1

    Set onBlur() programmatically?

    Is it possible to set the onBlur of
    a link or other focusable element
    programmaticall y?

    A search of the archive showed plenty of
    examples of setting the onBlur() for each
    link or form element when it was defined,
    but I am after something that can iterate
    all links in the page and add a common
    onBlur functionality to every one.

    [ I only require this to fix problems with
    particular pages, but then I need to apply
    the fix to whatever focusable elements are
    on the page. ]

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
  • Michael Winter

    #2
    Re: Set onBlur() programmaticall y?

    On Wed, 01 Sep 2004 18:47:44 GMT, Andrew Thompson <SeeMySites@www .invalid>
    wrote:
    [color=blue]
    > Is it possible to set the onBlur of
    > a link or other focusable element
    > programmaticall y?[/color]

    Yes. The code below works specifically with links (A elements with href
    attributes). If you can get object references, you can do a similar thing
    with any element that supports the blur intrinsic event.

    function myListener(evt) {
    evt = evt || window.event;
    }

    for(var i = 0, l = document.links, n = l.length; i < n; ++i) {
    l[i].onblur = myListener;
    }

    Be aware that the code above will destroy a listener defined by the onblur
    HTML attribute.

    [snip]

    Hope that helps,
    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.

    Comment

    • Andrew Thompson

      #3
      Re: Set onBlur() programmaticall y?

      On Wed, 01 Sep 2004 18:52:42 GMT, Michael Winter wrote:
      [color=blue]
      > On Wed, 01 Sep 2004 18:47:44 GMT, Andrew Thompson wrote:
      >[color=green]
      >> Is it possible to set the onBlur ..
      >> programmaticall y?[/color]
      >
      > Yes. The code below works specifically with links..[/color]

      Works perfectly for my purposes.

      Thank you muchly. :-)

      --
      Andrew Thompson
      http://www.PhySci.org/ Open-source software suite
      http://www.PhySci.org/codes/ Web & IT Help
      http://www.1point1C.org/ Science & Technology

      Comment

      Working...