Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery quiz app - highlight unordered list entry and call function
    primarykey
    data
    text
    <p>I'm creating a quiz app with JQuery, JQtouch &amp; Phonegap. The main screen shows a question in one unordered list, then 5 possible answers in the second list. The info is pulled from an sqlite db and the page dynamically created.</p> <p>I want the user to be able to click on a row in the answer ul, which will then highlight that row, unhighlight any other entries in the unordered (answer) list and call a function. I've looked through reams of example code, but can't get my head around the implementation. My page contains a div:</p> <pre><code>&lt;div id="answer_template2"&gt;&lt;/div&gt; </code></pre> <p>which is filled by the database query &amp; dynamically built page:</p> <pre><code> var questionHTML = "&lt;ul class=\"rounded\" id="question"&gt;"; var answerHTML = "&lt;ul class=\"rounded\" id="answers"&gt;"; for (var i=0; i&lt;results.rows.length; i++) { var row = results.rows.item(i); questionHTML += '&lt;li&gt;'+row['question_text']+'&lt;/li&gt;\n'; answerHTML += '&lt;li&gt;'+row['answer1_text']+'&lt;/li&gt;\n'; answerHTML += '&lt;li&gt;'+row['answer2_text']+'&lt;/li&gt;\n'; answerHTML += '&lt;li&gt;'+row['answer3_text']+'&lt;/li&gt;\n'; answerHTML += '&lt;li&gt;'+row['answer4_text']+'&lt;/li&gt;\n'; answerHTML += '&lt;li&gt;'+row['answer5_text']+'&lt;/li&gt;\n'; questionHTML +='&lt;/ul&gt;'; answerHTML +='&lt;/ul&gt;'; //alert(questionHTML); // ouput database result into question_template id section of page document.getElementById('question_template2').innerHTML = questionHTML; document.getElementById('answer_template2').innerHTML = answerHTML; </code></pre> <p>I've also got a function:</p> <pre><code> $("li").click(function() { alert("yes"); }); </code></pre> <p>which pops up the alert when a static li element is clicked but not when any of my dynamically created list elements are selected but can't figure out how to put it all together. Any help would be gratefully received! Thanks, Nick.</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