WordPress Code Snippets

A fresh mix of code snippets and tutorials

jQuery browser detection

85

Here’s a tasty little snippet for adding custom browser classes using jQuery.

This code checks for common browser types and adds a named class to the <html> element.

The following browsers are detected (for Mac & PC) using this method:

  • Opera – .opera / .opera-pc
  • Webkit – .webkit / .webkit-pc
  • Mozilla – .mozilla / .mozilla-pc
  • Internet Explorer 9 – .ie9 (PC only)
  • Camino – .camino (Mac only)
  • Chrome – .chrome / .chrome-pc
  • iPad/iPod/iPhone – .apple
  • Safari – .safari / .safari-pc

Customize as needed by removing unnecessary browsers and adding new ones.


Show Support

Like our new Facebook Page to show support!