Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Instead of triggering a click, I'd say it would be easier to just store a reference to the callback-function, and then use that reference both as your click-event callback and then just call i separately as well, instead of triggering a click event. Something like this:</p> <pre><code>var callback = function(){ if ($(this).parent().find("td.two, td.three").hasClass("toggled")){ $(this).parent().find("td.two").fadeOut(400); $(this).parent().find("td.three").fadeOut(400); $(this).parent().find("td.two").removeClass("toggled"); $(this).parent().find("td.three").removeClass("toggled"); } else { if ($(this).parent().find("td.three").hasClass("DoNotWant")){ $(this).parent().find("td.three").fadeOut(400); $(this).parent().find("td.three").toggleClass("DoNotWant"); } else { $(this).parent().find("td.three").fadeIn(400); $(this).parent().find("td.three").toggleClass("toggled"); } $(this).parent().find("td.two").fadeIn(400); $(this).parent().find("td.two").toggleClass("toggled"); } }; // Bind the click event $("td.one").click("click", callback); $(function () { // Instead of triggering a click, just call the function callback(); }); </code></pre> <p><em>In this example the callback for <code>td.two</code> has been left out for simplicity of the example</em></p> <p><strong>Side notes:</strong></p> <ol> <li><p>I believe there is a problem with your logic here, if you have more than one td that match your selector in the if-statement. In that case, the first element that matches will always be used when checking if it has class <code>toggled</code>. <code>.hasClass()</code> will evaluate the first element in the set of matched elements.</p></li> <li><p>You can make your code more efficient by using less DOM-traversing. In the callback, save a reference to the parent in a variable, and use that variable instead of calling <code>$(this).parent()</code> every time.</p></li> </ol>
    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.
 

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