Java Script Code to detect browser and apply CSS property

How to detect browser using Java Script Code and apply CSS property ?

As we all know that IE browser behaves unexpected in some cases and need some extra CSS property or change in CSS property to work/view perfectly.

Below is the code to detect browser and if browser is IE then apply or override some css property.

<script type="text/javascript">  if ((navigator.userAgent.indexOf("MSIE") != -1) || (!!document.documentMode == true)) //IF IE > 10
         {

             $('.mycssclass').attr('style', "margin:20px !important");
         }

         else {

         }

</script>


In above code if browser is IE then in HTML wherever 'mycssclass' will be found it will add/override margin property to 20px.

Comments

Popular

C# 6.0 New Features

SharePoint Interview Questions and Answers

Calling ASP.Net WebMethod using jQuery AJAX

What is Cloud Computing - A guide for beginners