Note that there are some explanatory texts on larger screens.

plurals
  1. POhowto catch jQuery for multiple links but not all
    primarykey
    data
    text
    <p>I'm trying to dig into jQuery but would like some feedback on how to do things the best way,</p> <p>I have a list with items, which each contains a hidden div that should show upon click on it's parent,</p> <pre><code>list div:ed item1 with link hidden div div:ed item2 with link hidden div .. </code></pre> <p>My current solution is to trace the calling link by it's id and then reusing that ID for showing the correct hidden one:</p> <pre><code>$(document).ready(function() { //jQ should only trigger on links with id="cmLinkINT" $("a").click(function() { //see if it's a comment request. var s = $(this).attr("id"); if (s.indexOf('cmLink') != -1) { //ok, it was a 'show'-link, get the id.. var j = s.substring(6); //ok, now I have the id i want to show (detailsINT) return false; } }); }); </code></pre> <p>What's not clear to me is the best approach,</p> <ul> <li><p>Should I use id for requesting a or trace the id of the parent div.</p></li> <li><p>How to avoid that the code triggers on any link? Class?</p></li> </ul> <p><strong>UPDATE</strong></p> <p>html example:</p> <pre><code>&lt;div class="unit"&gt; &lt;img class="unitImg" src="imgcache/some.jpg" width="98" height="98" alt="some"/&gt; &lt;div class="unitInfo"&gt; &lt;h1&gt;my unit&lt;/h1&gt; &lt;h2&gt;/further..&lt;/h2&gt; &lt;p&gt;&lt;a href="#" class="showDetails"&gt;show details...&lt;/a&gt;&lt;/p&gt; &lt;div style="visibility: hidden;" id="unitDetails2"&gt; &lt;p&gt;peekaboo...&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="unitGap"&gt;&lt;/div&gt; &lt;div class="unit" ...&gt; </code></pre> <p>Thankful for any feedback,</p> <p>regards</p> <p>//t</p>
    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