Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jQuery, how to find out if CSS selector "input[type=text]" is natively supported by browser?

In my CSS I have a rule that must be applied to all text fields (using the CSS3 selector input[type=text].

I also use jQuery. Some browsers like Internet Explorer 6 does not support that form for CSS selector. So my workaround is to add an extra classname in CSS:

input[type=text], .workaround_classname{
  /* css styling goes here */
}

And via jQuery then add the CSS class:

$('input[type=text]').addClass('workaround_classname');

The Question is: How do I make sure this rule only is invoked when CSS3 selectors are not natively supported?

like image 554
Jesper Rønn-Jensen Avatar asked Sep 09 '09 11:09

Jesper Rønn-Jensen


2 Answers

Why not set some useless css style and check if the style was applied. Only add the workaround class to the elements that don't have this style applied.

Only problem is I can't come up with a "useless" style you can use :-)

like image 200
Philippe Leybaert Avatar answered Oct 05 '22 05:10

Philippe Leybaert


This seems to incorporate something like you speak of:

http://www.w3avenue.com/2009/07/02/detect-support-for-css3-html5-with-modernizr/

like image 31
REA_ANDREW Avatar answered Oct 05 '22 05:10

REA_ANDREW