Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, remember that there can only be one <code>#delete</code> ID on the page. If there's more than one, you'll have issues, and should make it a class <code>.delete</code>.</p> <p>If the <code>#delete</code> element isn't present when the page loads (dynamic) you can use <code>.live()</code>, which will take care of handling the event for you, no matter when you add the element.</p> <pre><code>$('#delete').live('click', function(){ ... }); </code></pre> <p>But note that this will <em>still</em> fire the event on the <code>.day-main-diary</code> as well.</p> <p>One other option would be to call <code>.delegate()</code> on the <code>.day-main-diary</code> (as long as it is there when the page loads). This is similar to <code>.live()</code> but is more localized.</p> <pre><code>$('.day-main-diary').delegate('#delete', 'click', function() { ... }); </code></pre> <p>This also will fire the <code>click</code> on the <code>.day-main-diary</code>. Not sure what the expected behavior is.</p> <ul> <li><a href="http://api.jquery.com/live/" rel="nofollow noreferrer">http://api.jquery.com/live/</a></li> <li><a href="http://api.jquery.com/delegate/" rel="nofollow noreferrer">http://api.jquery.com/delegate/</a></li> </ul> <p>Yet another option would be to test the <code>e.target</code> of the click in the <code>.day-main-diary</code> click handler. If it is the <code>#delete</code> do one thing, if not, do another.</p> <pre><code>$('.day-main-diary').click(function( e ) { if(e.target.id === 'delete') { // run code for the delete button } else { // do something else } }); </code></pre> <p>Otherwise, still assuming that the <code>#delete</code> is dynamic, you can bind the <code>.click()</code> <em>when</em> you create it.</p> <pre><code>$('&lt;span id="delete"&gt;delete&lt;/span&gt;').click(function( e ) { // your code // uncomment the line below if you don't want the // click event to fire on .day-main-diary as well // e.stopPropagation() }) .appendTo('day-main-diary'); </code></pre>
    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. 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