Discovery: first child support

How to detect using JavaScript if the browser supports CSS selector :first-child?

+3
source share
2 answers

You can simply use this rule :first-childto set a specific value, and then get the computed style in Javascript to see if the rule applies :first-child, for example.

<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 verified. I do not have IE 6.)

+4
source

, jQuery, . , , . , ? , ?

jQuery, jQuery, // , CSS?

"" , quirksmode.org, , IE, , , IE8.

+2

Source: https://habr.com/ru/post/1764316/


All Articles