Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2> ::WARNING:: <br /> .selector has been deprecated as of version 1.7, removed as of 1.9 </h2> <p>The jQuery object has a selector property I saw when digging in its code yesterday. Don't know if it's defined in the docs are how reliable it is (for future proofing). But it works!</p> <pre><code>$('*').selector // returns * </code></pre> <p><strong>Edit</strong>: If you were to find the selector inside the event, that information should ideally be part of the event itself and not the element because an element could have multiple click events assigned through various selectors. A solution would be to use a wrapper to around <code>bind()</code>, <code>click()</code> etc. to add events instead of adding it directly.</p> <pre><code>jQuery.fn.addEvent = function(type, handler) { this.bind(type, {'selector': this.selector}, handler); }; </code></pre> <p>The selector is being passed as an object's property named <code>selector</code>. Access it as <code>event.data.selector</code>.</p> <p>Let's try it on some markup (<a href="http://jsfiddle.net/DFh7z/" rel="noreferrer">http://jsfiddle.net/DFh7z/</a>):</p> <pre><code>&lt;p class='info'&gt;some text and &lt;a&gt;a link&lt;/a&gt;&lt;/p&gt;​ $('p a').addEvent('click', function(event) { alert(event.data.selector); // p a }); </code></pre> <hr /> <p><strong>Disclaimer</strong>: Remember that just as with <code>live()</code> events, the selector property may be invalid if DOM traversal methods are used.</p> <pre><code>&lt;div&gt;&lt;a&gt;a link&lt;/a&gt;&lt;/div&gt; </code></pre> <p>The code below will NOT work, as <code>live</code> relies on the selector property which in this case is <code>a.parent()</code> - an invalid selector.</p> <pre><code>$('a').parent().live(function() { alert('something'); }); </code></pre> <p>Our <code>addEvent</code> method will fire, but you too will see the wrong selector - <code>a.parent()</code>.</p>
    singulars
    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