Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to work with multiple ids in jquery?
    primarykey
    data
    text
    <p>Following is my HTML code :</p> <pre><code> &lt;table&gt; {foreach in smarty starts} &lt;tr&gt; &lt;td valign="top" id ="show_answer"&gt;&lt;p id="show_ans"&gt;&lt;b&gt;View Answer : &lt;/b&gt;&lt;/p&gt;&lt;/td&gt; &lt;td align="right" width="7%" valign="top"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" id ="hide_answer"&gt;&lt;b&gt;Answer is here&lt;/b&gt;&lt;br/&gt;&lt;p id="hide_ans" &gt;Hide Answer&lt;/p&gt;&lt;/td&gt; &lt;td align="right" width="7%" valign="top"&gt; &lt;/td&gt; &lt;/tr&gt; {foreach in smarty ends} &lt;/table&gt; </code></pre> <p>My jQuery code is here :</p> <pre><code>&lt;script&gt; $(document).ready(function(){ $("#show_ans").click(function(){ $("#show_answer").hide(500); $("#hide_answer").show(500); }); $("#hide_ans").click(function(){ $("#hide_answer").hide(500); $("#show_answer").show(500); }); }); &lt;/script&gt; </code></pre> <p>Actually there are multiple such <code>&lt;tr&gt;</code> tags and multiple related ids (i.e multiple <code>show_ans</code> and <code>show_ans</code> ids). Now when I'm trying with my code it is functioning properly only for the first record as it matches with only first ids combination.</p> <p>But I have to make the code workable for each of the ids combination individually. But I don't know how to assign different ids generated dynamically and use them in my jQuery code. In short, the functionality should work for individual <code>&lt;tr&gt;</code>, so that the ids should be unique and the jQuery function should work appropriately.</p> <p>Can anyone help me to solve this issue? Thanks in Advance.</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