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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:01:21+00:00 2026-05-24T16:01:21+00:00

I have a site I’m building in PHP, and have a page that loads

  • 0

I have a site I’m building in PHP, and have a page that loads data dynamically from mySQL. It uses list items that the user clicks on, causing a _POST to the database, thus not allowing me to customize the CSS of the page they’re now seeing. I’m wondering if there’s a way to dynamically set the css class of the <li> they’ve clicked, as to highlight it. Problem is, if they press another list item, I have to un-highlight the old one. Anyone have input on the best way to go about this?

  • 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-24T16:01:23+00:00Added an answer on May 24, 2026 at 4:01 pm

    Assuming you’re submitting the POST requests via AJAX, add something like this (I’m going to assume you’ve already got the AJAX part out of the way)

    // var context is a previously identified container for the list items
    
    var items = context.getElementsByTagName('li');
    for (var i = 0; i < items.length; i++) {
        items[i].addEventListener('click', function() {
            // do AJAX stuff
    
            // remove the "highlight" class from all list items
            for (var j = 0; j < items.length; j++) {
                var classname = items[j].className;
                items[j].className = classname.replace(/\bhighlight-class-name\b/i, '');
            }
    
            // set the "highlight" class on the clicked item
            this.className += ' highlight-class-name';
        }, false);
    }
    

    Demo here – http://jsfiddle.net/jYdMB/

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

Sidebar

Related Questions

So I have site list on certain pages that basically just have links to
I have site with these files and foldes: /index.php ( that include php files
I need to have site.com/index.php?s=super-smash-bros-baww-SUzohN redirected to site.com/super-smash-bros-baww-SUzohN . How can I do that?
I have a site I made really fast that uses floats to display different
If I have site.com/page/about.php How can I remove the sub directory and file extension?
I am confused with MySQL connections. I have site that receives heavy requests during
i have a site that uses globalize3 gem (https://github.com/svenfuchs/globalize3) and i'm currently adding the
For example I have site http://localhost/site In IIS I set that 404 error causes
I want to have site wide default settings for all jQuery validation uses on
I have a site that allows users to vote on images. Each image has

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.