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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:41:51+00:00 2026-06-02T23:41:51+00:00

I would like to alternate background colors for odd and even list items in

  • 0

I would like to alternate background colors for odd and even list items in my unordered list. This worked great until I added javascript inside of each list item. If I remove the javascript, the background color alternates as it should. With the javascript, I can see in firebug that each list item looks like it is even.

The reason why I need to have the javascript inside of each list item is because I am dynamically displaying each list item from the database, and assigning classes based upon the application id ($apid).

My css to alternate background color of list items:

ul.version li:nth-child(odd) {
background: #EEE;
}

ul.version li:nth-child(even) {
background: #FFF;
}

And the applicable code in my php page:

<ul class="version">

                                <li class="versionheader">

                                    <ul>
                                        <li class="appname">
                                            Application
                                        </li>

                                        <li class="appvidlink">
                                            Video
                                        </li>

                                        <li class="appwish">
                                            Wishlist
                                        </li>

                                        <li class="appimplement">
                                            Implemented
                                        </li>
                                    </ul>



                                </li>



                            <?php
                            //get child applications
                            $application_id_result = mysql_query("SELECT apid from products_app_categories WHERE cid = '$catid'");
                                while($application_id_row = mysql_fetch_array($application_id_result)) {

                                    $apid = $application_id_row['apid'];



                            //see if user already has app in their wishlist
                            $application_wished_result = mysql_query("SELECT COUNT(apid) FROM products_wishlist_users WHERE apid = '$apid' AND uid = '$uid'");
                                while($application_wished_row = mysql_fetch_array($application_wished_result)) {




                                    if($application_wished_row['COUNT(apid)'] < 1) {

                                        $appwished = false;
                                    } else {
                                        $appwished = true;
                                    }



                            $application_result = mysql_query("SELECT * FROM products WHERE child = '1' AND parent_id = '$pid' AND id = '$apid'");
                                while($application_row = mysql_fetch_array($application_result)) {

                                    $apname = $application_row['name'];

                                    ?>


                                    <li class="app app_<?php echo $apid; ?> <?php if($appwished) { echo 'appwished'; } ?>">

                                        <ul>
                                            <li class="appname">
                                                <?php echo $apname; ?>
                                            </li>

                                            <li class="appvidlink">
                                                
                                            </li>

                                            <li class="appwish">
                                                <?php if(!$appwished) {
                                                    echo '<a class="btn addtowishlist addtowishlist_' . $apid . '">Add</a>';
                                                } else {
                                                    echo '<span class="checkmark"></span>';
                                                } ?>
                                            </li>

                                            <li class="appimplement">
                                                <?php if(!$implemented) {
                                                    echo '<a class="btn addtoimplemented">Yes</a>';
                                                } else {
                                                    echo '<span class="checkmark"></span>';
                                                } ?>
                                            </li>
                                        </ul>



                                    </li>



                                    <script type="text/javascript">

                                        $('.addtowishlist_<?php echo $apid; ?>').click(function(){

                                            $.get("wishlist/wishlistupdate.php?uid=<?php echo $uid; ?>&apid=<?php echo $apid; ?>");

                                            $("#wishlistapps").load("wishlist/wishlistdisplay.php?uid=<?php echo $uid; ?>");


                                            $("li.app_<?php echo $apid; ?>").addClass("appwished");

                                            return false;
                                        });


                                    </script>





                                <?php   
                                } } }?>

                        </ul>
  • 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-02T23:41:52+00:00Added an answer on June 2, 2026 at 11:41 pm

    set background color with javascript at end of the script.

    $('ul.version li:even').css('background-color','#EEE');
    $('ul.version li:odd').css('background-color','#FFF');
    

    make sure to load jquery in header 😡

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

Sidebar

Related Questions

i would to have alternate 2 colors of rows, like the first black, the
I would like to alternate between gray and white as background from one line
Is there any alternative to this: Organizations.Include(Assets).Where(o => o.Id == id).Single() I would like
Would like to be able to set colors of headings and such, different font
I'm not much of a database guru so I would like some advice. Background
I would like to store some Application-Related Metadata for Files, and NTFS Alternate Data
I would like to develop an application which runs as a background service .
I have this report that I generate in an aspx page. I would like
This alternate & normal give different color to the background of the rows If
I would like to have my Python program run in the background as 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.