• Stars
    star
    204
  • Rank 192,063 (Top 4 %)
  • Language
    JavaScript
  • Created about 15 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🔮 Generate HTML from CSS selectors

Satisfy that selector!

Satisfy is a stand-alone (no dependencies) JavaScript function for generating HTML from CSS selectors. It's incredibly simple.

This:

satisfy('div a');

Returns the following DOM structure:

<div>
    <a></a>
</div>

You can use attribute selectors and a numerical psuedo-class to manipulate the produced structure further:

satisfy('ul li:5 span[innerHTML="item"]');

And that would produce this:

<ul>
    <li><span>item</span></li>
    <li><span>item</span></li>
    <li><span>item</span></li>
    <li><span>item</span></li>
    <li><span>item</span></li>
</ul>

And sibling combinators (note: ~ and + do the same thing in this context):

staisfy('div span + a');

Output:

<div>
    <span></span>
    <a></a>
</div>

Note: satisfy() returns a NodeList containing the elements you want. It's not a real array.

Other minor features

You can set a boolean property with a no-value attribute expression (Thanks to Kangax):

satisfy('input[type=checkbox][checked]');
satisfy('audio[autoplay]');

You can also set an element's innerHTML like so:

satisfy('div a[innerHTML=blah]');
// or:
satisfy('div a[html=blah]);

It's also possible to set multiple classes:

satisfy('a.b.c.d'); // => <a class="b c d"></a>

jQuery

If you're using jQuery then you can use Satisfy like so:

jQuery.satisfy('div a:5').prependTo('body');

jQuery.satisfy returns a jQuery instance containing all of the elements produced from whatever selector you pass to it. This makes it possible to use any of jQuery's methods... So, instead of:

jQuery('<div><a/></div>').appendTo(foo);

... you can do:

jQuery.satisfy('div a').appendTo(foo);

Improvements in 0.3

I re-wrote most of the code in 0.3. The mechanism now used for creating elements is mostly fragment-based and the selector is processed in reverse.

More Repositories

1

sonic.js

➿ Create loopy loading animations
HTML
821
star
2

findAndReplaceDOMText

🔍 Find and replace DOM text
JavaScript
776
star
3

operative

🐕 Seamlessly create Web Workers
JavaScript
655
star
4

relevancy.js

📊 Sort/Weigh strings by relevance
JavaScript
286
star
5

cron.js

Cron for JavaScript. Still in development.
JavaScript
122
star
6

SIML

Simplified Markup
JavaScript
97
star
7

vic.js

Validation & Input Correction abstraction
JavaScript
91
star
8

mini

A tiny selector engine; only the essentials
JavaScript
57
star
9

at.hn

JavaScript
44
star
10

parseScripts

A simple abstraction to simplify the process of adding your own JavaScript enhancements. Read README.txt
32
star
11

ZergRush

JavaScript
27
star
12

parsers-built-with-js

Trying to build a list of parsers/interpreters/converters built in JavaScript.
27
star
13

jsapi-info

Publically configurable, centralised store of JS libs' API source code
JavaScript
25
star
14

jQuery.Interface

Sub classing jQuery methods to creating your own classes with DOM interfaces
JavaScript
21
star
15

string.prototype

Cool String.prototype additions
JavaScript
20
star
16

redoku

🔡 Little Regex "Sudoku" game generator
HTML
18
star
17

debug

debug.js is an in-browser JavaScript error-reporter
JavaScript
14
star
18

sonic-creator

JavaScript
13
star
19

javascript-dom-general

Random JavaScript
JavaScript
13
star
20

commentData

Keep per-element metadata in HTML comments.
JavaScript
13
star
21

rGen

Generate strings to fulfill basic regular expressions using rGen.
JavaScript
12
star
22

SiteTraverser

A JavaScript "toolkit" you can use to create bookmarklets specifically designed to crawl websites looking for the presence or lack of certain features
JavaScript
12
star
23

embedHelper

"embedHelper" is a tiny helper-library used to aid in the unobtrusive inclusion and execution of 3rd party scripts - it's used within the 3rd party script.
JavaScript
10
star
24

PhotoWall

JavaScript
8
star
25

cssDataRequest

Cross-domain Ajax via CSS
JavaScript
8
star
26

jQuery-Commandments

I am not a prophet of the revered John Resig, but I have done my best to compile a list of commandments. One applicable to jQuery programming and the other applicable to jQuery plugin authoring.
JavaScript
7
star
27

twtl

twtl is a tiny in-browser testing library
JavaScript
6
star
28

jquery-costume-party

JavaScript
6
star
29

lewis

JavaScript
6
star
30

jQuery.macroSelect

Macro selectors incl jQuery method names -- one step beyond what CSS3 offers.
JavaScript
5
star
31

CanvasThing

JavaScript
5
star
32

receptive

JavaScript
3
star
33

lamb

JavaScript
2
star
34

tik

MVC server for node
JavaScript
1
star
35

proxyfoo

ESHarmony Proxies stuff
JavaScript
1
star