Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to fetch the dynamically created element by its ID in jquery
    text
    copied!<p>Initially adding the element statically like below: </p> <pre><code>&lt;td valign="top" id="description_div"&gt; *&lt;table class="des_box" id="comment_div"&gt; &lt;tr&gt;&lt;td class="head" id=file_comments&gt; The function comments &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;td class="comment" id="test_point_comment_info"&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt;* &lt;/td&gt; </code></pre> <p>Dynamically adding the element as below : </p> <pre><code>$("#description_div").append( '&lt;table class="des_box1" id=comment_div&gt;&lt;tr&gt;&lt;td class="head" id=file_comments&gt; The function comments &lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="comment" id=test_point_comment_info_' + id + '&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt;') </code></pre> <p>Now, when I try to fetch the element by its id (that is by "comment_div") ... I am not able to retrieve the dynamically created element. But able to fetch the static element by using $("#comment_div") </p> <p>I am trying to do following on the element : </p> <pre><code>$("#comment_div").show(); </code></pre> <p>tried .live() ....but was not able to fetch the dynamic element.</p> <pre><code>$("#comment_div").live().show(); </code></pre> <p>check box code : </p> <pre><code>&lt;li&gt;&lt;input type="checkbox" name="comment" /&gt;Comment&lt;/li&gt; </code></pre> <p>actual functions where am trying to fetch the element: </p> <pre><code>$("#checkbox_div input:checkbox").click(function() { var division = "#" + $(this).attr('name') + "_div"; $(division).show(); } function SetCheckboxes(checkbox_data) { //SetCookie('pre_checkbox', "1111111111111111") var checkbox_data = GetCookie('pre_checkbox'); if (checkbox_data == null) { SetCookie('pre_checkbox', "1111111111111111") checkbox_data = GetCookie('pre_checkbox'); } checkbox_array = new Array("owner", "test_time", "bp", "single_use", "num_of_test", "pause", "clearall", "clearclass", "clearmax", "closeall", "qeinbat", "m_lint","geck","header","comment","feature"); for ( i = 0; i &lt; checkbox_data.length; i++) { var checkbox_name = checkbox_array[i]; var value = checkbox_data[i]; var division = "#" + checkbox_name + "_div"; if (checkbox_name=="geck" || checkbox_name=="header" || checkbox_name== "comment" || checkbox_name=="feature"){ console.log("entering_loop_as_expected") if (value == "1") { //alert("1"); $("#checkbox_div input[name='" + checkbox_name + "']").attr("checked", "checked"); $(division).show(); } else { $(division).hide(); } continue; } </code></pre> <p>Please help me out on this . Thanks!</p>
 

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