Code Monkey home page Code Monkey logo

comb.js's Introduction

 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'])

comb.js's People

Contributors

dominiccharleyroy avatar jokeofweek avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.