Forum Moderators: open

Message Too Old, No Replies

Need IE conditional inside a DIV tag

         

JAB Creations

10:13 pm on Jul 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I need to put an IE condition inside of a DIV tag to support a :hover effect by inserting Javascript with onmouse attributes without breaking validation for the W3C or breaking AAA accessibility standards.

encyclo

12:36 am on Aug 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Certainly doable, but what markup have you got so far, and what trouble are you having with it?

JAB Creations

4:13 am on Aug 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I was trying to do this...

<div class="vote" onmouseover="this.className='voteh'" onmouseout="this.className='vote'">

But keep the onmouse attributes as part of the HTML comments/conditions.

<div class="vote" <!--[if IE]>onmouseover="this.className='voteh'" onmouseout="this.className='vote'"><![endif]-->>

But I need to make sure this still passes through the validator and doesn't screw up Opera and Gecko.

bedlam

8:06 am on Aug 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But I need to make sure this still passes through the validator and doesn't screw up Opera and Gecko.

This is why the .htc method used in the whatever:hover [google.com] method is actually pretty good; since no other browser but IE can understand what the weird nonstandard htc 'behavior' property means, and because it won't choke the validator if you stick it inside an IE conditional comment, you can solve almost all the major problems you mention at once.

This is also the reason for rewriting the elements of a specific class or id using the DOM [google.com] when - and only when - the page is loaded by IE.

The basic strategy is this:

  1. On page load, get all the elements with a specific class together
  2. Loop through all of them and write a hover behaviour into each one of them

If I recall correctly, there is some cross-browser issue with writing events such as 'onmouseover' into html using the DOM, but there are alternate methods - one approach can be seen in some of the more modern techniques for generating image rollovers [google.com], and there's always the javascript forum [webmasterworld.com] for really tricky problems...

So to summarize, you'd have something like this in the page <head>:


<!--[if IE]>
<style>
body {
behavior:url(path/to/file.htc);
}
</style>
<![endif]-->

...followed by a script that rewrites the desired elements when the page loads.

-B

encyclo

1:21 pm on Aug 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One important point for using IE conditional comments - with IE7 just around the corner, you will need to adjust them to take into account the fact that IE7 is going to support
:hover
on arbitrary elements in much the same way as Firefox. So you must make sure you are not just adding the code for all versions of IE, only versions lower than IE7.

<!--[if [b]lt IE 7[/b]]>
<style>
body {
behavior:url(path/to/file.htc);
}
</style>
<![endif]-->

If you want to continue using your current code, then you can't have a conditional comment within the

div
tag as this is not permitted within the HTML spec. However, you might find you can nest another
div
within the first one, and apply the IE styles to that:

<div class="vote"><!--[if lt IE 7]><div class="ie-vote" onmouseover="this.className='voteh'" onmouseout="this.className='vote'"><![endif]-->

But in both cases you are hitting against your stated primary objective, with is WCAG AAA accessibility. Your code might pass a check with an accessibility validator, but it may still contain accessibility problems. Are we talking about a mouseover menu here? What happens when the user is navigating using the keyboard?