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 9147711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:03:52+00:00 2026-06-17T11:03:52+00:00

I am creating a list dynamically. I used the onclick event to call a

  • 0

I am creating a list dynamically. I used the onclick event to call a javascript and this works, what I can not do is get the selected item from the list to have a different color.

This is the code example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>`enter code here`
    <script src="scripts/jquery.js" type="text/javascript"></script>
    <link href="stylesheets/jquery.mobile.css" rel="stylesheet" type="text/css" />
    <script src="scripts/jquery.mobile.js" type="text/javascript"></script>
    <script>

        $(document).ready(function () {
            var $al = $("#mylist");
            $al.append("<li ><a id='a1' href=\"#\" rel=\"external\" onclick=\"test('selected test 1'); return false\">TEST 1</a></li>");
            $al.append("<li ><a id='a2' href=\"#\" rel=\"external\" onclick=\"test('seleced test 2'); return false\">TEST 2</a></li>");
        });

        function test(text) {
            $("#divtest").html(text);
        } 

        $("#myList li a").click(function () {
                $('#myList li > div').each(function (index) {
                    $(this).removeClass("ui-btn-active");
                });
                var p = $(this).parent();
                $(p).addClass('ui-btn-active');
            });

    </script>
</head>
<body>
    <div data-role="page" id="profile">
        <div data-role="header" data-position="fixed">
        </div>
        <!-- /header -->
        <div data-role="content">
            <ul id="mylist" data-role="listview" data-inset="true">
            </ul>
        </div>
        <div id='divtest'>

        </div>
        <!--/content-->
        <div data-role="footer" data-position="fixed">
        </div>
        <!--/footer-->
    </div>
</body>
</html>
  • 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-17T11:03:53+00:00Added an answer on June 17, 2026 at 11:03 am

    To do this you need to call .addClass and .removeClass from your list item. Depending on the color you want you will have to remove/add certain classes. For starters you can add the class ui-btn-active to the items.

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

Sidebar

Related Questions

I am creating a list dynamically.I want to call a function on onclick event
Why does this attempt at creating a list of curried functions not work? def
I'm creating list dynamically in javascript. I want to break the long word in
I'm creating a list of class Task in a way such as this. List<Task>
I have a list of dynamically created TextViews for which I am creating context
I am dynamically creating a combobox like this: public Control GenerateList(Question question) { //
I'm dynamically creating a drawable shape in my list view and i'm setting the
I'm creating a ListView where each list item has a LinearLayout which I would
I am creating a menulist popup list dynamically. I the editable and open attributes
I'm creating a play list dynamically with m.Playlist() and then adds tracks with the

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.