Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4059484
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:12:54+00:00 2026-05-20T15:12:54+00:00

I’m creating a quiz app with JQuery, JQtouch & Phonegap. The main screen shows

  • 0

I’m creating a quiz app with JQuery, JQtouch & 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.

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:

<div id="answer_template2"></div>

which is filled by the database query & dynamically built page:

    var questionHTML = "<ul class=\"rounded\" id="question">";
    var answerHTML = "<ul class=\"rounded\" id="answers">";

    for (var i=0; i<results.rows.length; i++)
    { 
        var row = results.rows.item(i); 
        questionHTML += '<li>'+row['question_text']+'</li>\n';
        answerHTML += '<li>'+row['answer1_text']+'</li>\n';
        answerHTML += '<li>'+row['answer2_text']+'</li>\n';
        answerHTML += '<li>'+row['answer3_text']+'</li>\n';
        answerHTML += '<li>'+row['answer4_text']+'</li>\n';
        answerHTML += '<li>'+row['answer5_text']+'</li>\n';

    questionHTML +='</ul>';
    answerHTML +='</ul>';

    //alert(questionHTML);

    // ouput database result into question_template id section of page
    document.getElementById('question_template2').innerHTML = questionHTML;
    document.getElementById('answer_template2').innerHTML = answerHTML;

I’ve also got a function:

    $("li").click(function() 
{
    alert("yes");
});

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:12:55+00:00Added an answer on May 20, 2026 at 3:12 pm

    First of all, jQuery events are only bound to elements it finds when you execute the selector.

    There are two common ways of getting around this:

    1. Use .live() or .delegate() to bind your events to the document (or some other container) and have them check for a target that is within an LI.

      $("li").live('click', function() { alert("hi"); });
      
    2. Re-bind your handlers to the newly created content:

      // ouput database result into question_template id section of page
      document.getElementById('question_template2').innerHTML = questionHTML;
      document.getElementById('answer_template2').innerHTML = answerHTML;
      $("#answer_template2 li, #question_template2 li").click( handler );
      

    Also, just as a side note – $("#question_template2").html(questionHTML); is a little safer to use rather than injecting your HTML directly to innerHTML. It will give jQuery a chance to unbind/cleanup the memory for the elements you are removing by destroying innerHTML.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.