How to detect, does browser support the CSS :first-child
selector?
views:
52answers:
2
+2
A:
I don't think there is a jQuery function to find out support for this. I expect if it does exist, it is going to be quite complicated. Are you really sure you need this? Care to share why?
If you can use jQuery anyway, why not add a jQuery statement to assign the class/property/whatever to the desired element, instead of relying on CSS?
As a "manual" answer, looking at the quirksmode.org compatibility table, the selector is fully supported in all modern browsers except the IE family which seems to have problems even in IE8.
Pekka
2010-09-11 20:21:48
Ive found this page http://api.jquery.com/jQuery.support/ but dont know how to use it
Happy
2010-09-11 20:25:45
@WorkingHard: jQuery.support cannot test for `:first-child` support.
BoltClock
2010-09-11 20:26:20
@WorkingHard I would ask myself first *why* I need this in the first place.
Pekka
2010-09-11 20:28:31
+4
A:
You could just use that :first-child
rule to set some specific value, and then get the computed style in Javascript to see if the :first-child
rule is applied, e.g.
<style>
#foo { width: 200px; }
#foo:first-child { width: 400px; }
</style>
<span><span id="foo"></span></span>
<script>
if ($('#foo').width() < 400)
alert('first-child not supported.');
</script>
(This is not tested. I have no IE 6.)
KennyTM
2010-09-11 20:23:55
This is nice and an exact answer to the question, +1. Although I have the feeling the basic premise of *having to find this out in the first place* is the result of a faulty design decision.
Pekka
2010-09-11 20:27:37
@WorkingHard true. But I don't think you'll get around introducing an element like that (although you should be able to set `display: none` so it's hidden). Still, the basic question to me still is: *Why do you need this?*
Pekka
2010-09-11 20:35:45