2 ms·
This is very cool, great work! Although I think you should make it clear in the read me that it only supports 2 basic jQuery-like selectors (by id '#id' and by
by MattBearman 13y ago
This is very cool, great work! Although I think you should make it clear in the read me that it only supports 2 basic jQuery-like selectors (by id '#id' and by class '.class'), ie: none of the following will work - 'div', '[name="test"]', '.class1.class2', '.class1 .class2', 'div.class .class2[data-test="thing"] > em#id:last-child' - I realise that last one should never be used in real life.
Some of these could be implemented with things like getElementsByTagName, getElementsByAttribute, and recursive calling when spaces are found. I may even do a pull request with these if I find time this weekend :)
Have you looked into using querySelectorAll? I'd be interested to know if it's slower and by how much.
- bndr 13y agoThe reason why I left only the ID and Class selectors is because they are the fastest. Here are some test cases: http://jsperf.com/getelementsbyclassname-vs-queryselectorall/35 http://jsperf.com/getelementsbyclassname-vs-queryselectorall...