When you have written a few different pieces of JavaScript you come to realize that IE and Firefox have different opinions on what works and what doesn’t work. What this means is you may need to have different JavaScript firing if the current browser is IE! Here is a little example of how we can detect if the current browser is IE:
<!–[if IE]>
<script type="text/javascript">
//add a conditional comment block that only is run if the browser is IE
ie = true;
</script>
<![endif]–>
<script type="text/javascript">
//combine with jQuery if needed
$(document).ready(function(){
if(!ie){
alert("Not an IE browser");
}else{
alert("IE browser");
}
});
</script>
And there you have it, you can now target IE with JavaScript in 3 easy steps!