Internet Explorer support for nth-child selector
I am using IE9.js from this project.
For the most part it works well, enabling support for css such as opacity in Internet Explorer 7. However it doesn't support the :n开发者_如何学运维th-child() selector. Is there a way around this purely using javascript? By that I mean my CSS would be read by the javascript and the css attributes applied to the matching elements. I am aware that this problem can be solved by using classes on the elements or using jQuery (or other frameworks) to select the elements. However this is not ideal.
Ideally I want to have my presentation code in one place (css) not scattered around my project.
Edit Looks like this IE library might do it: link.
For non-IE6 browsers, you can use the adjacent sibling selector, if the type of child elements are always the same. For example, if you want select the 5th child li element in a list:
ul:first-child > li+li+li+li+li { ... }
There are a lot of ways to accomplish this but the easiest would be to adopt a helper library like jQuery
. It supports those selectors across all browsers and also gives you a lot more tools.
If you can't add the dependency, just choose a similar library and extract that particular implementation (make sure the license allows it).
Sorry but I didn't see your reference to jQuery in the post... Please disregard the above. http://selectivizr.com/ seems a nice tool, though.
精彩评论