May 4, 2008     Registering events on an empty div in IE 6

IE (6 at least, not sure about 7), has this behavior where it won’t register events on divs that it sees as “empty”. This came up in a project where I need to use invisible, positioned divs with event handlers on them.

But you can get around it, as long as the whole div can be invisible. The way I’m doing so is by using the star hack to add an IE-only style to the div. This style gives the div a background-color, and sets the opacity to zero. That way, the div is invisible to the user, but according to the browser there’s still something “there”, so it will properly register events.

The style would look something like this:

* html .activediv{ //star hack targets only IE
background-color:#FFFFFF; //background color makes the browser register events, like onclick
filter:alpha(opacity=0); //opacity filter hides it from the user
}

Again, I haven’t tested this in IE 7.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment