jokeofweek / comb.js Goto Github PK
View Code? Open in Web Editor NEWComb.js is a simple JavaScript DOM element selector.
License: MIT License
Comb.js is a simple JavaScript DOM element selector.
License: MIT License
Comb.js Created by: Dominic Charley-Roy ======================== Comb.js is an incredibly simple DOM traversal utility which allows you to query the DOM for elements matching a given selector. The comb function returns an array of all the elements matching the passed selector. Building a selector is simple. Selector rules are separated by the '>' character. Comb allows you to find elements matching the following rules: '#elementId' - This will search for an element matching the ID 'elementId' '.elementClass' - This will search for all elements with the 'elementClass' class 'tag' - This will search for all elements with the 'tag' tag, such as 'p' or 'div' '*' - This will match all children nodes of the previously matched elements. Examples : - To find the element with the ID 'right', you would do: comb('#right'); - To find all elements with the class 'large', you would do: comb('.large'); - To find all div elements, you would do: comb('div') - To find all paragraph elements within a div with ID 'blueSquare', you would do: comb('#blueSquare>p') - To find all elements with class 'red' which are in a DIV, you would do: comb('div>.red') - To find all the children elements of an element with ID 'header', you would do: comb('#header>*'); You may also apply an OR rule using the '|' token. Examples : - To find all img elements within a div with either ID 'left' or ID 'right', you would do: comb('#left|#right>div') - To find all elements which either have a H1 or H2 tag, you would do: comb('h1|h2') You can also pass a function to be applied to all elements found by the comb function. If a function is passed, comb will call it and pass the element as a parameter. It essentially traverses the array of elements and calls the function on each element. Examples: - To alert the inner HTML of all elements with class 'red', you would do: comb('.red', function(element){ alert(element.innerHTML); }); Note that, as the comb function returns a list of the elements, you can cache the returned elements for future access Examples: - To cache all divs for future access: var divs = comb('div'); You may also pass an array of selector strings to the function in order to select more than one group of elements which cannot be picked through the OR operator. Examples: - To select all selements which are either images inside divs or have class ".red", you would do: comb(['div>img', '.red'])
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.