Reputation: 8104
I have this snippet of code:
<script type="text/javascript">
$(window).load(function() {
if(!$.browser.msie){
$('#myDiv').animate({opacity: 1}, 300);
} else if ($.browser.msie) {
$('#myDiv').css({opacity:1});
}
});
</script>
How can I say the same thing using the " : something ? somethingElse "
syntax?
Thanks in advance?
Upvotes: 0
Views: 3399
Reputation: 25322
Not sure I got the question, however:
$.browser.msie ? $('#myDiv').css({opacity: 1}) : $('#myDiv').animate({opacity: 1}, 300);
Also, I'm not an expert of IE anymore, but I wonder if you could do something like:
$('#myDiv').animate({opacity: 1}, $.browser.msie ? 0 : 300);
That should be applied immediately, and made it more readable with an external variable:
var speed = $.browser.msie ? 0 : 300;
$('#myDiv').animate({opacity: 1}, speed);
Or something like that.
Upvotes: 7
Reputation: 1074385
You can do it like this:
$(window).load(function() {
$.browser.msie ? $('#myDiv').css({opacity:1}); : $('#myDiv').animate({opacity: 1}, 300);
});
I wouldn't recommend it for at least two reasons (browser sniffing, and readability), but you can.
Another way:
$(window).load(function() {
$('#myDiv')[$.browser.msie ? 'css' : 'animate']({opacity:1}, $.browser.msie ? undefined : 300);
});
...but that's even worse. ;-)
Upvotes: 4