Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>EDIT:</strong> Based on further clarification, try this:</p> <pre><code>$('#one').bind('click dblclick', function( event ) { var id = event.target.id; if(id == "one" || id == "two" || id == "three") { if(event.type == "click") { // code for click event } else { // code for double click event } } });​ </code></pre> <hr> <p><strong>EDIT:</strong> Based on our conversation under another answer, it seems like you want the <code>#one</code> element to be clickable, but <em>none</em> of its child elements. If that is right, try this:</p> <pre><code>$('#one').click(function() { // code to run when `one` is clicked. }).children().click(function( event ) { event.stopPropagation(); }); </code></pre> <p>Now if there's any text in <code>#one</code>, the code for that element will fire, but it will not fire when you click any children of <code>#one</code>.</p> <p>Let me know if that was what you wanted.</p> <hr> <p><strong>EDIT:</strong></p> <p>If you are saying that you will have a dynamic number of elements inside <code>#one</code>, and the <em>last</em> one will not get the event, then do this:</p> <pre><code>$('#one').delegate('div:not(:last-child)', 'click dblclick', function( event ) { if(event.type == 'click') { // do something for the click event } else { // do something for the double click event } });​ </code></pre> <p>Note that this assumes there will not be nested divs. Results may be unexpected if there are. Also, the <code>#one</code> element doesn't fire events. Only its children.</p> <hr> <p><strong>Original answer:</strong></p> <pre><code>$('#one,#two,#three').bind('click', function(){ // code for click event }) .bind('dblclick', function() { // code for double click event }); </code></pre> <p>Or replace <code>.bind</code> with <code>.live</code> if you <em>really</em> need it.</p>
 

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