Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding a click handler to toggle divs
    primarykey
    data
    text
    <p>I want to add click handler to <code>&lt;a id='3'&gt;</code>. I have a main <code>div</code> in which <code>&lt;link-div&gt;</code>s are getting added dynamically and shown as a list. I have only posted the code that is buggy minus the CSS and other goodies. I cant figure out how to isolate that <code>&lt;a&gt;</code> for each <code>&lt;link-div&gt;</code>. Idea is to click and show hidden <code>&lt;div id="hide"&gt;</code> based on whether it resides in first <code>&lt;link-div&gt;</code> or 2nd.</p> <p>Here is <a href="http://jsfiddle.net/Ntt33/" rel="nofollow">fiddle Example</a></p> <h2>HTML</h2> <pre><code> &lt;div id="main"&gt; &lt;div id="link-div"&gt; &lt;div class="name-div"&gt; &lt;a id='1' href='javascript:void(0);' &gt;(11)&lt;/a&gt; &lt;a id='2' href='javascript:void(0);'&gt; Apples &lt;/a&gt; &lt;a id='3' href='javascript:void(0);'&gt;[click to see more]&lt;/a&gt; &lt;div id="hide"&gt;more apples &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="link-div"&gt; &lt;div class="name-div"&gt; &lt;a id='1' href='javascript:void(0);' &gt; (44) &lt;/a&gt; &lt;a id='2' href='javascript:void(0);'&gt; Bats &lt;/a&gt; &lt;a id='3' href='javascript:void(0);'&gt;[click to see more]&lt;/a&gt; &lt;div id="hide"&gt; more bats&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p></p> <pre><code>## Javascript $("#main div div div").hide(); /*hide 'more apples', more bats'*/ $("#main div div div &gt; a ").click(function() { /* this is where I need help */ $("#main div div div").toggle(); /*show 'more apples' or 'more bats' */ }); </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.
 

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