Skip to content

kissyteam/query-selector

Repository files navigation

query-selector

querySelectorAll in javascript

query-selector NPM downloads Build Status Coverage Status Dependency Status Bower version node version

browser support

use on node

require jsdom

var querySelectorAll = require('query-selector');
var jsdom = require("jsdom").jsdom;
var doc = jsdom('<html><div id="t"><span>1</span><span>2</span></div></html>');
var time = Date.now();
console.log(doc.querySelectorAll('#t span', doc).length);
console.log(doc.querySelectorAll('#t span', doc)[0].innerHTML);
console.log(Date.now()-time);
time = Date.now();
console.log(querySelectorAll('#t span', doc).length);
console.log(querySelectorAll('#t span', doc)[0].innerHTML);
console.log(Date.now()-time);

use standalone on browser

<script src="/build/query-selector-standalone-debug.js"></script>
<div id="t">
    <span>1</span>
    <span>2</span>
</div>
<script>
    console.log(querySelectorAll('#t span'));
</script>