Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery click event fires the first time, but not the second
    primarykey
    data
    text
    <p>This is the HTML I'm working with:</p> <pre><code>&lt;ul id="categories"&gt; &lt;li&gt;&lt;a href="#cargo"&gt;Cargo Trailers&lt;/a&gt;&lt;/li&gt; &lt;div class="dropdown"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#utility"&gt;Utility Trailers&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/ul&gt; </code></pre> <p>I have written a jQuery script to hide the dropdown div. The dropdown div appears the first time the click event is fired. Once the li in the dropdown div is selected and switches places with the first li in the #categories ul, clicking on the li will not bring up the dropdown div.</p> <p>Here is the jQuery:</p> <pre><code>jQuery(document).ready(function($) { // hide the dropdown div $('#categories &gt; div').hide(); /* Click the drop down arrow function */ var $listHeader = $('#categories &gt; li'); $listHeader.click(function() { if ( $('#categories &gt; div:hidden') ) { //show the drop down $('#categories &gt; div').show(); } else { //hide the drop down $('#categories &gt; div').hide(); } }); /* Click a list-item in the drop down function */ $('#categories &gt; div a').click(function() { /* actions to change the title to the newly selected item */ // hide the ul $('#categories &gt; div').hide(); // move the clicked item to the header $(this).prependTo('#categories &gt; li'); // move the previous title to the dropdown and sort $('#categories &gt; li &gt; a:eq(1)').prependTo('#categories &gt; div &gt; ul &gt; li:empty'); // Reset the listHeader variable $listHeader = $('#categories &gt; li'); // cancel default browser action return false; }); }); </code></pre>
    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.
 

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