Hide div after 10 seconds

OIC. Not a problem in Opera, of course. And who cares about those who persist in using inferior browsers … :smiley:

The onclick event will capture any click events that occur on elements within it as well, such as the link.

It is easily possible to modify things so that the onclick event only occurs on the anchor element itself, instead of from the p element.

That would just mean changing this code:


p.innerHTML = '<a href="#">Hide</a>';
p.onclick = function () {

so that the second line targets the anchor itself.


p.innerHTML = '<a href="#">Hide</a>';
p.getElementsByTagName('a')[0].onclick = function () {

But then you must ask yourself if there is any benefit in doing things that way.

Sorry to drag this up, but this is totally new to me and belongs here:

On the 7 Deadly JS Sins article Paul posted about in [url=http://www.sitepoint.com/forums/showthread.php?t=662004]another thread, Chris Heilmann mentioned (in the comments) using -1 tabindex to bring keyboard focusability to any element. I don’t use tabindex normally but found this in a [url=http://dev.opera.com/articles/view/accessible-drag-and-drop/]linked article:

Ensure objects can be reached using the keyboard

All objects that are draggable must be reachable using the keyboard alone. Some elements are already reachable using the keyboard alone, such as standard interface elements and anchors. For elements that do not usually receive focus, you can use the tabindex attribute.

There are two useful values: a tabindex attribute value of puts elements in keyboard tab order identical to the order they appear in the source; a negative value for the tabindex attribute does not put the element into the keyboard tab order, but allows it to receive programmatic focus. Using a negative tabindex attribute value is useful if you do not want to clutter the keyboard tab order and control navigation by defining custom keystrokes, for example using the Up and Down cursor keys to navigate through a menu.

Ha, I never knew that! Good to know for when I’m doubt about keyboard focus and JS (maybe can also use it for in-page skip links problem too?!?).

*edit yes, they seem to have a typo: “a tabindex attribute value of puts elements” value of what? I assume 1.

I don’t know where he came up with that bit of information, but it wasn’t in the HTML specification. It says, for the tabindex attribute:

This value must be a number between 0 and 32767.

There’s not one word about negative values being valid, nor how user agents should treat them. I’d advise against relying on non-standard behaviour (and HTML5 is not a standard yet, in case that’s where this comes from).

The article is about ARIA but if I understand correctly, ARIA isn’t just HTML5 (if it was, I’d not bother reading the article).

I’d be curious to test it (tabindex), though.