0

I am absolutely new in JavaScript and jQuery and I have the following problem.

I have to modify a jQuery script so that it has a different behaviour when the browser is Chrome.

This is my script:

$(document).ready(function () {
  $("thead.opening").click(function () {
    alert("INTO second function");
    $(this).next().css('width', '10000000 em');
    alert(modified);
    $(this).next().css('width', '10000000 em');
    $(this).next().css('display', 'table-row-group');
    alert($(this).next().css('display'));
  });
});

As you can see this script perform this statement that sets the display: table-row-group CSS settings:

I want that if the browser is Chrome the script set:

$(this).next().css('display', 'block');

Can I do it in some way?

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
  • use modernizer http://modernizr.com/ detecting user agents is very unreliable – fuzzybear May 04 '15 at 10:48
  • Since you are absolutely new to this stuff, I can but warmly recommend you `console.log()` instead of `alert()` :) Also, cache DOM requests in variables, e.g. `var $elem = $(this).next()`, so you can reuse `$elem` many times without querying the DOM again and again. Performance boost. You can also write `$elem.css({'width':'1000em' , 'display':'table-row'})` in one command. Finally, `$(function(){` is a shorthand to `$(document).ready(function () {.` – Jeremy Thille May 04 '15 at 10:50

1 Answers1

2

You can use:

var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
$(this).next().css('display', is_chrome ? 'block' : 'table-row-group');

Find chrome browser : original post from SO

Community
  • 1
  • 1
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125