$()

Description: Create a new jQuery selection object due to given parameters.

… – miscellaneous parameters
any parameter accepted by the jQuery function itself.

Tip: With .$(…) you can switch the jQuery selection within any invocation chain.


See jQuery API for $().


Examples with crate a jQuery selection

Example #1: repeated blinking (like in the old days with the deprecated <blink> element)

By using .toggleClass() the CSS class switches from being added and removed after every interval timeout.

In this example the interval timeout is set to 400 milliseconds.

$('.blink').repeat(400).toggleClass('blink');

This is a blinking text.

See also another example for the same task using iterated timeouts instead.


Example #3: a simple inline click handler

The handler-less version of .on() allows to create small event handlers very easily. In this example the span element is shifted right with each button click.

$('button').on('click').next().css({left:'+=20px'});

Watch me moving!


Example #5: create dynamic tables with instant loops

Imagine you want to add very many table rows automatically so you can fill them with dynamic content.
E.g. a 30 x 200 sized table. Then you need only one callback method creating each cell. The rest is done via a single jQuery chain:


function createCell(x,y) {
    $('<td>').text(x+':'+y).appendTo(this);
}

$.repeat().$('<tr>').repeat(createCell).until(30)
  .appendTo('tbody').until(200);
My dynamic data:

Example #14: wait a timeout after each click before blinking

With the concatenation of two .wait()s we achieve a single short blink.

Instead of attaching an event handler explicitly we start an infinite event loop for the "click" event. Repeat loops are always sequential, i.e. the next iteration can start only if the previous one ended. You can see this behavior when double- or triple-clicking the button.

$('.example button').repeat('click').prev()
   .wait(500).addClass('blink')
   .wait(300).removeClass('blink');

That text blinks half a second after hitting .