Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery Append Not Working Properly
    primarykey
    data
    text
    <p>I am using sockets with JQuery, In on message call of sockets I want to append a div in my html page, but as soon as the page is loaded I see an extra div already appended, How can I prevent it from appending on load of the page.</p> <p>Secondly When a div is appended There is a button with id=answerit inside div on which I added onclick functionality. but when the div is appended and try to click on the answer it button it does not call the onclick function, but when the page is reloaded then it works</p> <p>My code is </p> <pre><code> Student.socket.onmessage = function (message) { //alert(message.data); $( document ).ready(function() { var str = message.data; var ques = str.split(":"); var questionId = ques[0]; var questionText = ques[1]; var question = "&lt;div class='span11' style='border:2px solid; border-radius:5px; background-color:#b0c4de;'&gt;"+ "&lt;div style='width:30px; float:left;'&gt;" + "&lt;div class='voteup'&gt;&lt;a id="+questionId+" vote='true' title='This answer is useful' style='cursor:pointer'&gt;up&lt;/a&gt;&lt;/div&gt;"+ "&lt;div class='votedown'&gt;&lt;a id="+questionId+" vote='false' title='This answer is not useful' style='cursor:pointer'&gt;down&lt;/a&gt;&lt;/div&gt;"+ "&lt;/div&gt;"+ "&lt;div style='float:left;'&gt;"+ "&lt;div style='margin-top:5px' class='span10'&gt;"+ "&lt;span&gt;"+questionText+"&lt;/span&gt;"+ "&lt;button id="+questionId+" style='float:right' class='answerit btn'&gt;Answer It&lt;/button&gt;"+ "&lt;button id="+questionId+" style='float:right' class='showAnswers btn'&gt;Show Answers&lt;/button&gt;"+ "&lt;/div&gt;"+ "&lt;/div&gt;"+ "&lt;/div&gt;"; $('#studentsQuestions').append(question); }); }; </code></pre> <p>HTML is </p> <pre><code>&lt;div id="studentsQuestions"&gt;&lt;/div&gt; </code></pre> <p>Every time I load a page I see an extra div already present with undefined text</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    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