Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have a table like this:</p> <pre><code>&lt;table id='test'&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="#"&gt;test&lt;/a&gt;&lt;/td&gt; &lt;td&gt;Hi&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;a href="#"&gt;test1&lt;/a&gt;&lt;/td&gt; &lt;td&gt;Hi&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>The most basic selector is going to look like this:</p> <pre><code>$('a').click(function(e) { alert('test!'); return false; }); </code></pre> <p>This is simply binding something to <em>all</em> the links in the document. Want more control?</p> <pre><code>$('#test').find('a').click(function(e) { alert('test!'); return false; }); </code></pre> <p>Which is essentially saying: "find me all the <code>&lt;a&gt;</code> elements inside the element with id of <code>test</code> and bind this click handler to it" - jQuery is so powerful because it handles sets of objects this way.</p> <p>This is just the tip of the iceberg, though! You can get much more in-depth. What if you only want to bind the <code>&lt;a&gt;</code> elements that appear in the 1st <code>&lt;td&gt;</code> relative to the <code>&lt;tr&gt;</code>? No problem:</p> <pre><code>$('#test').find('td:nth-child(1) a').click(function(e) { alert('test'); return false; }); </code></pre> <p>Although jQuery does have an <code>each</code> function that lets you iterate through a set of elements, when it comes to binding events you will rarely need it. jQuery loves sets and will do anything you ask it to to a set of elements if it makes any sense.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload