When the mouse is moved to the UL LI list, the border color of the Top Hover is reverted back to default

Can you assist me with this issue?

I need to modify the code below so that the border color remains blue while a user selects an item from the UL LI list.

Here is an image showing the current problem:

https://i.sstatic.net/DS7hO.png

And here is a picture of the expected outcome:

https://i.sstatic.net/aWsUh.png

For reference, here is the Fiddle link: https://jsfiddle.net/g825e2o2/

CSS Markup:

<style type="text/css>
   * {
    font-family: Segoe UI;
    font-size: 9pt;
}
.select dd, .select dt, .select ul {
    margin: 0px;
    padding: 0px;
}
/* CSS styling continues... */
</code></pre>

<p>The remaining HTML code:</p>

<pre><code><script type="text/javascript">

$(document).ready(function() {

    $(".select dt a").click(function() {
        var select = $(this).closest('.select');
        select.find('ul').toggle();
    });
    
    /* JavaScript functions continue... */

});
</script>

</head>

<body>

    <dl id="reqtype" class="select">Fruits
        <dt><a href="#"><span data-val=""></span></a></dt>
        <dd>
            <ul>
                <li><a data-val="" href="#"> </a></li>
                    <span class="header-list">- List -</span>
                <li><a data-val="apples" href="#">Apples</a></li>
                <li><a data-val="Bananas" href="#">Bananas</a></li>
                <li><a data-val="Oranges" href="#">Oranges</a></li>
            </ul>
        </dd>
    </dl>

    <br><br>

    <dl id="action" class="select">Status
        <dt><a href="#"><span data-val=""></span></a></dt>
        <dd>
            <ul>
                <li><a data-val="" href="#"> </a></li>
                <li><a data-val="ACTIVE" href="#">ACTIVE</a></li>
                <li><a data-val="ON HOLD" href="#">ON HOLD</a></li>
                <li><a data-val="CLOSED" href="#">CLOSED</a></li>
            </ul>
        </dd>
    </dl>

</body>

</html>

Answer №1

If you're looking to change the color of certain elements on your webpage, a simple JavaScript snippet can help you achieve that. All you need to do is include the code below in your JS file and customize it according to your preferences:

$('.selected').click(function(e){
    $(this).css("background-color", "blue");
    $(this).css("color", "white");
});

Next, make sure to add the "selected" class to the specific links or elements you want this effect applied to in your HTML file. Here's an example:

<ul id="navlinks">
    <li><a href="#" class="selected">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#" class="selected">Services</a></li>
</ul>

With these changes implemented, you should see the desired color alterations take effect. Feel free to adjust the JavaScript snippet further to match your CSS requirements.

This solution was inspired by a similar approach found here.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for incorporating fading text and a CTA into your content block

I am looking to protect the full content of my blog posts and allow access only to subscribed members. I want readers to see just a glimpse of the article before it disappears, prompting them to take action with a Call to Action (CTA) like in the fading te ...

Show the table within the flex container

I have a question about CSS. Is it possible to apply display: table to a flex item? Whenever I try to do this, the layout doesn't behave as expected - specifically, the second flex item does not fill the available vertical/horizontal space. .conta ...

Has the querystring hack become outdated?

For a long time, I have been adding a query string to my CSS link whenever I made changes that needed to be reflected on client machines: <link href="/Resources/styles/styles.css?v=1" rel="stylesheet" /> Lately, I've noticed that Chrome seems ...

CSS positioning problems thoroughly elucidated

I'm facing two issues that I can't seem to resolve. My goal is to recreate a design similar to the one found at https://i.sstatic.net/XfPqm.jpg. My first issue is with adjusting the box in the header to stay aligned next to my headline tags. The ...

What could be causing my jQuery to only toggle the first arrow in my HTML?

I am facing an issue with a series of divs generated from data, each containing an arrow that should toggle an expandable section. Strangely, only the first div is functioning properly: toggling the arrow icon and revealing the content upon click. When th ...

Is there a way to modify Style Properties in JavaScript by targeting elements with a specific class name using document.getElementsByClassName("Class_Name")?

I am seeking a solution to change the background color of multiple div boxes with the class name "flex-items" using JavaScript. Below is my current code: function changeColor(){ document.getElementsByClassName("flex-items").style.backgroundColor = "bl ...

When a div slides down on page load, the div will slide up when a button is clicked

I am trying to make a div slideDown on page load. The goal is to have the div automatically slideDown after 2 seconds, which contains a responsive image and a button named "z-indexed". However, I am having trouble getting the same div to slideUp when the z ...

What is the best way to include additional text in a dropdown menu?

I'm trying to add the text "Choose Country" in a drop-down list before the user selects their country. example1 Here is the line of code I used: <option data-hidden="true"> Choose Country </option> However, the phrase does ...

Creating eight equal sections within HTML <div> elements using Bootstrap

I am brand new to Angular. I need to design something like this: https://i.sstatic.net/Zcb9i.png However, I'm struggling to find the right solution. Here is what I have so far: https://i.sstatic.net/7hsrk.png. Having been a backend developer, I&ap ...

Switch the image source when hovering over a text menu

Currently, I have been using the following code to switch between images. However, what I actually want to do is change the image when hovering over the title link of the image. onmouseover="this.src='Images/img.png'" onmouseout="this.src=' ...

Create an HTML button on the homepage that directs users to the "about" page

I've been struggling to make a button in my Ionic app navigate to a different page upon clicking. Despite being new to Ionic, I've spent hours trying to solve this issue. Below is the HTML code in home.page.html: <ion-header> &l ...

How can you attach a d3 graphic to a table that was created automatically?

Calling all experts in d3, I require urgent assistance!! On this web page, a JSON is fetched from the server containing 50 different arrays of numbers and related data such as 90th percentiles, averages, etc. A table is dynamically created with the basic ...

Setting the transition time for adding or removing components in ReactJS CSS

As the list component changes in size based on its children, it tends to move around abruptly. Applying transition: 'all 0.3s ease' doesn't resolve this issue since it's the layout that is affected by the number of children rather than ...

The like button animation works perfectly for individual posts, but for multiple posts, only the like button on the first post

Having an issue with the like button code on a single news feed. The button works for the first post, but when clicking on other posts, it only affects the first post button. I am using post UI and looping the UI based on the total post count without Javas ...

What's the best way to retrieve the nth row of a div once the mouse hovers over

$(document).ready(function() { $('div').on('mouseover', function() { alert($('div:eq(' + this + ')')); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></ ...

Wrapping header text in Vuetify's v-data-table

Struggling with wrapping the header text on a v-data-table component. I've tried applying styles, but only tbody elements are affected. The header (thead element) remains unchanged. Any suggestions on how to get custom styling for the header? For ins ...

How can we nest a div within the outermost parent element?

Consider a scenario where there are 3 different divs named grandParent, Parent, and Child. Although the parent's tag is placed inside the grandParent, due to the use of position: absolute; property, the parent ends up being displayed outside the grand ...

Interacting with Cassandra using PHP

I am attempting to execute a SELECT query from the Cassandra Database using a PHP script. The connection is successfully established through PHP. Here is the query: $session = $cluster->connect($keyspace); $result = $session->execute("SELEC ...

Problem with CSS hovering on images when hovering on links?

While attempting to add 2 hover images to my website, I encountered an issue where a black border appeared in the middle of the images. This was caused by the hover effects on the links. Below is the code snippet: a:hover,a:active { color:Black; o ...

In the present technological landscape, is it still considered beneficial to place Javascript at the bottom of web pages?

As a beginner in web programming, I've recently delved into Javascript. A hot debate caught my attention - where should javascript be placed, at the top or at the bottom of a webpage? Supporters of placing it at the top argue that a slow loading time ...