tags:

views:

42

answers:

1

How do I make this code work in all browsers?

<script>
var $j = jQuery.noConflict();

$j(document).ready(function(){
    if ($j.browser.msie) {
        $j('.round').append('<div class="tl"></div><div class="tr"></div><div class="bl"></div><div class="br"></div>');
    }
});
</script>
+5  A: 

Unless I'm missing something, just take out your if:

var $j = jQuery.noConflict();

$j(document).ready(function(){
  $j('.round').append('<div class="tl"></div><div class="tr"></div><div class="bl"></div><div class="br"></div>');
});

Now that if was probably there for a reason, maybe some IE specific CSS hackery going on? In that case it's a CSS issue, not a JavaScript one outside of this. Something like the jQuery corners plugin may be what you're ultimately after. Other/newer browsers support rounded corners natively, this is mainly an IE fix.

Nick Craver
you mean i just need to remove this part `if ($j.browser.msie)`
metal-gear-solid
@metal-gear-solid - Correct, that prevents anything inside from running in IE, as a general rule you want to avoid using [`$.browser`](http://api.jquery.com/jQuery.browser/) whenever possible.
Nick Craver
ok then what is the difference between using `if ($j.browser.msie)` or to keep js inside IE conditional comment?
metal-gear-solid
@metal-gear-solid - They work in a different way, Conditional comments are interpreted or not by the browser where as `$.browser` [parses the UserAgent](http://github.com/jquery/jquery/blob/master/src/core.js#L739) which is both less reliable, and undesirable. For example, what if IE9 supported what you wanted (and it probably does), so things that didn't used to work...you'd be now denying your users for no reason, this is why [feature detection via `$.support`](http://api.jquery.com/jQuery.support/) is preferred.
Nick Craver