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

  • SEARCH
  • Home
  • 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 8807787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:27:17+00:00 2026-06-14T02:27:17+00:00

I have a listview which I created with JavaScript/jQuery. When I click on a

  • 0

I have a listview which I created with JavaScript/jQuery. When I click on a listitem I have to execute code.

Scenario 1:
I use this code:

$("div#home ul#one li").live('click', function() { console.log('click') });

this code picks up the click, but it picks it up twice. So when I click on a listitem it outputs two console.logs

Scenario 2:
I have this code for another list which was created in the normal index.html file.

$("div#home ul#two li").off('click').on('click', function() { console.log('click') });

This code doesn’t execute the code twice.

Is there anyway I could get Scenario 2 working on the JavaScript created listview? (Any other suggestions are welcome too)

  • 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-06-14T02:27:19+00:00Added an answer on June 14, 2026 at 2:27 am

    The problem is that you’re not binding your on listener in the right place, you are declaring in a pageinit handler for ANY page to add youron listener to the li:$("div#home").on('click','li', function() { console.log('click') });

    Thus you are attaching one listener on the div#login page and attaching a redundant 2nd listener on the second div#home page. When you click the li one event is fired to two listeners and you get the two clicks.

    What you should be doing is in your $(document).on('pageinit', function() wrap your on listener declaration in a conditional that checks which page you’re on:

    if ($(this).attr(id') === 'home'){
         $("div#home").on('click','li', function() { console.log('click') });
    }
    

    That’s the simple solution, what you really should be doing is branching your code based on which page fired the pageinit event and calling the correct code based on it. See: my guide on structuring jQM Apps.

    The gist of it is attach a data attr to your div[data-role=page] etc that describes your page then call separate code for each page. (instead of using the ID like in this example, because you can easily have more than one instance of a page in multi-page jQM apps)

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

Sidebar

Related Questions

I have a ListView which contains custom rows. This custom row has following UI
I have created an layout which contains the listview. I have added a button
I have a ListView which I've created a custom view for each row. My
I have created a ListView which contains a list of items. Each item in
I have created a listview which displays all the people in the database. But
I have a listview in which's groupstyle, i have defined an expander(code below), i
I have created a listview which displays the installed applications. It has app icon
I have created a dynamic listview which contains a CheckBox.what I want is at
I have created a custom listview which has Image + Text + checkbox. How
I have created a listview which pulls the scores of users held in a

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.