0

I found this code to detect android native browser:

var nua = navigator.userAgent;
var is_android = ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 &&     nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1));

but how can I create function to repleace css after detection?

I know I should use something like that:

$('jQuery selector').css({"css property name":"css property value"});

but I don't now how :(

On the same page is other function that is using jquery.

5
  • Change css of which element? Commented Jan 5, 2016 at 11:33
  • @p0mian check this link api.jquery.com/css Commented Jan 5, 2016 at 11:34
  • Don't set/reset CSS properties, instead add/remove classes. Commented Jan 5, 2016 at 11:35
  • I can't think a case where you want to change 1 or 2 elements based on a specific browser. Perhaps you want to change to another CSS file, containing all the changes for Android devices? Commented Jan 5, 2016 at 11:35
  • If it is just for detecting android, can't we have it like this if(nua.indexOf('Android ') > -1). Commented Jan 5, 2016 at 11:59

3 Answers 3

1
var nua = navigator.userAgent;
var is_android = ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 &&     nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1));

if (is_android){
  //for eg you want to remove border of a div with id #container
  $('#container').css({"border":"none"});
  //Best is to have a class created in css with which ever property you want to remove
  // if the class was .green-color
  $('#container').removeClass('green-color');
}
Sign up to request clarification or add additional context in comments.

Comments

0

The best way is to add a classname to <html> or <body> tag, with that trick you can modify the pure CSS without jquery selectors and DOM manipulation, making it really flexible and performance:

 if(is_android) { 
       $('html').addClass('android');
 } else {
       $('html').removeClass('android');
 }

and then with CSS as simple as this:

 h1 { color:blue; }
 .android h1 { color:green; }
 .android body {background: black; }

Comments

0

both Url as following that hopefully can help you to deal with your problems

How can I use JQuery to replace CSS background image and maintain gradient?

Replace CSS property with jQuery conditional

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.