Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery bind on multiple anchor
    primarykey
    data
    text
    <p>I would like to bind the same event to a list of anchor link. Why this does not work?</p> <p>Markup:</p> <pre><code>&lt;a tabindex="0" href="#contactRoles" class="fg-button fg-button-icon-right ui-widget ui-state-default ui-corner-all" id="contactAdd"&gt; &lt;span class="ui-icon ui-icon-triangle-1-s"&gt;&lt;/span&gt;Aggiungi contatto&lt;/a&gt; &lt;div id="contactRoles" class="hidden"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#1" class="contactRole"&gt;Cliente&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#2" class="contactRole"&gt;Controparte&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#3" class="contactRole"&gt;Avvocato&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#4" class="contactRole"&gt;Avv. Controparte&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#5" class="contactRole"&gt;Altre parti&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#6" class="contactRole"&gt;Domiciliatario&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#7" class="contactRole"&gt;Pubblico Ministero&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#8" class="contactRole"&gt;Giudice&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#9" class="contactRole"&gt;Istruttori&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#10" class="contactRole"&gt;Studio Legale&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>jQuery:</p> <pre><code>$('#contactAdd').menu({ content: $('#contactRoles').html(), width: 150, showSpeed: 300 }); $("a.contactRole").click(function(event){ event.preventDefault(); alert("Link " + $(this).attr("href") + " clicked"); }); </code></pre> <p>Where am I wrong?</p> <p><strong>EDIT</strong>: @everybody: Yes the script is wrapped by a $(document).ready(...)</p> <p>For further information consider that the div with class "hidden" is hidden and can only be viewed by a click on another anchor as you can see from this screenshot. <img src="https://i.stack.imgur.com/a6ktE.png" alt="alt text"></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.
 

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