<!DOCTYPE html>
<
html
>
<
head
>
<
title
>
How to write a browser-specific code using jQuery?
</
title
>
<
script
src
=
</
script
>
</
head
>
<
body
style
=
"text-align: center;"
>
<
h1
style
=
"color: green;"
>
GeeksforGeeks
</
h1
>
<
h3
>
How to write a browser-specific
code using jQuery?
</
h3
>
<
input
type
=
"button"
id
=
"btn"
value
=
"Click Here!"
>
<
br
><
br
>
<
span
class
=
"GFG"
></
span
>
<
script
>
$(document).ready(function () {
$("#btn").click(function () {
if (navigator.userAgent.indexOf("Chrome") != -1) {
$(".GFG").text('Chrome Browser').css({
"background-color": "green",
"color": "white",
"font-size": "26px",
"font-weight": "bold"
});
}
else if (navigator.userAgent.indexOf("Firefox") != -1) {
$(".GFG").text("Firefox Browser").css({
"background-color": "red",
"color": "white",
"font-size": "26px",
"font-weight": "bold"
});
}
else if ((navigator.userAgent.indexOf("MSIE") != -1)
|| (!!document.documentMode == true)) {
$(".GFG").text('Internet Explorer').css({
"background-color": "blue",
"color": "white",
"font-size": "26px",
"font-weight": "bold"
});
}
else {
$(".GFG").text('Unknown Browser').css({
"background-color": "yellow",
"color": "white",
"font-size": "26px",
"font-weight": "bold"
});
}
});
});
</
script
>
</
body
>
</
html
>