Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason this is happening is because the .click() function only binds to the appropriate elements at the time the code is first evaluated (onReady). Since the prepended items didn't yet exist in the DOM, these elements didn't get the click() event bound to them. You COULD put the .click() binding call AFTER the .prepend() function calls, but who knows what other changes you'll want to make to the DOM afterward. Using .live() will make sure that EVERY element which matches the CSS select pattern <code>'#contact_box'</code> will get the function bound to its onClick() event no matter when the element is added to the DOM.</p> <p>Whew. Hope that was clear. Now consider these changes:</p> <pre><code>// The below line was changed to a shorthand notation which means the same as $(document).ready(function(){}); $(function() { $('#contact').click(function() { $('#contact_box').remove(); $('.menu_item_content').prepend('&lt;div class="menu_box" id="contact_box"&gt;Contact INFO goes in this box.&lt;/div&gt;'); }); $('#about').click(function() { $('#about_box').remove(); $('.menu_item_content').prepend('&lt;div class="menu_box" id="about_box"&gt;About info goes in this box.&lt;/div&gt;'); }); $('#twitter').click(function() { $('#twitter_box').remove(); $('.menu_item_content').prepend('&lt;div class="menu_box" id="twitter_box"&gt;Twitter&lt;/div&gt;'); }); // //remove single items // //nothing below this fires for some reason? // Changes here. $('#contact_box').live('click',function() { $('#contact_box').remove(); }); // And changes here. $('#about_box').live('click',function() { $('#about_box').remove(); }); // And changes here. $('#twitter_box').live('click',function() { $('#twitter_box').remove(); }); }); &lt;style&gt; .menu_item { display:inline; font-family:Tahoma; font-size:20px; } .menu_spacer { display:inline; font-family:Tahoma; font-size:45px; } &lt;/style&gt; &lt;div class="menu"&gt; &lt;div class="menu_items"&gt; &lt;div class="menu_item" id="contact"&gt;CONTACT&lt;/div&gt; &lt;div class="menu_spacer"&gt;/&lt;/div&gt; &lt;div class="menu_item" id="about"&gt;ABOUT&lt;/div&gt; &lt;div class="menu_spacer"&gt;/&lt;/div&gt; &lt;div class="menu_item" id="twitter"&gt;TWITTER&lt;/div&gt; &lt;/div&gt; &lt;div class="menu_item_content"&gt; &lt;/div&gt; &lt;/div&gt; </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. 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