Browser detection vs Feature Detection
Or Why is browser sniffing not a recommended practice?
I recomend you some research about Feature Detection, and why it's better than Browser Detection or Browser Sniffing. This article on the jQuery learning center explains both techniques, and why feature detection is better than browser detection.
To summarize, quoting the article I refer:
Browser detection
Browser detection is a method where the browser's User Agent (UA) string is checked for
a particular pattern unique to a browser family or version.
Feature detection
Specific feature detection checks if a specific feature is available, instead of
developing against a specific browser. This way, developers can write their
code for two cases: the browser does support said feature, or the browser
does not support said feature.
While Browser detection seems to be an easy solution, there are several problems:
Other browsers other than your target may have the same issue.
If we target a specific browser for different functionality, we implicitly
exclude any browser we did not account for.
User Agents are unreliable.
User Agents are set by the client browser and are also user-configurable. While
the user may change this string, the browser's feature support remains the same.
As said by @Garath on his answer, I recomend you modernizr as feature detection library. You can also take a look at jQuery.support, but the jQuery team does not recommend using it as it's intended for jQuery's internal use.