The hover action in the Jquery Accordion does not activate when a section has been opened before

I'm facing a problem with my jQuery accordion menu.

After opening and closing a section, the ':hover' effect stops working only for that specific section. However, it continues to work for other sections that haven't been clicked yet.

If I open all sections, then ':hover' functionality stops working for all sections.

Any help would be greatly appreciated.

Thank you

Ramona

You can view a quick sample of the code showcasing the issue on jsFiddle through this link.

http://jsfiddle.net/yUyEC/

Try hovering over the sections and notice the background positions shift. Click on one section, then another, and go back to hover over the previous section. Some strange behavior is happening :)

Please keep in mind that the div slide positioning may appear off in this example, but it's fine in the actual version. The issue, however, is well-demonstrated here.

Answer №1

To start, I would first ensure that the code is valid by making the necessary adjustments:

<div class="sidebar_game_header">
  <a href="http://www.apple.com/">
   <img src="http://robertmegone.com/jsfiddle/images/icn_1.png" alt="Game 4 Icon"/>
   <div class="sidebar_game_header_text">Game 4</div>
  </a>
</div>

It is important to note that nesting a block-level div inside an inline-level a element can lead to potential issues with browser error recovery when incorporating interactivity through JavaScript functions.

Furthermore, there may not be a need for positioning or floating in this menu, as arranging the image and text within the "header" using inline blocks should suffice without any unnecessary movement.

JSFiddle: Link Here


I made some modifications to separate the CSS from the jQuery for improved functionality, ensuring that hover states are activated smoothly.

You can view the updated example here. This revised version achieves hover states, background movements, and adds a class to the "open" accordion header for a consistent look.

If needed, you can specify link color by targeting the a tag in the CSS separately instead of relying solely on the color property of the enclosing div.

Hope these changes enhance the functionality of your code!🚀

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

Avoid showing an image when it is outside the div container

Within a single div, I have an assortment of images that are dynamically repositioned using JQuery. $("#"+carElem).css({"left": pos.left+50 +"px"}); I am currently utilizing absolute positioning (although relative positioning yields the same outcome). Is ...

Introducing LightZAP v2.54 (silent update2), the revolutionary Lightbox custom plugin that seamlessly launches when the page loads using the designated tag name (#img1)

As I have the LightZAP plugin installed on my website as an alternative to Lightbox, I am looking to trigger it (to display an image gallery with a specific image) when the page loads using the following link: index.html#img1, if possible. I have come acr ...

Guide to populating a div with post content upon clicking a link

When the link is clicked, I wanted a script that would load the content without reloading the whole page. However, it seems like the actual page is being loaded into my featuredv div instead of just the post content. It feels like when the link is clicked, ...

Finding the perfect label for effective web scraping with rvest

I am struggling to identify the correct tag to extract the specific text from a webpage. The HTML snippet in question is provided below. The text I am aiming to scrape is "Melbourne Storm has achieved 4 tries Brisbane Broncos has achieved 2 tries" Despite ...

Is there a way to reference a different CSS class within another class?

Currently, I am working on creating a navbar using React. In this navbar, I have three components for the menu bar: text, logo, and buttons. The background color of the navbar is set to transparent, while the components are black by default. However, whe ...

Communicating parameterized information to ASP.NET server-side with jQuery by utilizing $.post method, rather than resorting to $.ajax

I am utilizing jQuery to store data in my database within an MVC 5 application using ASP.NET. The information sent includes an id parameter of type int and an array of data objects. While sending the data to the server-side works with $.post, it results i ...

Maintain button in active state following click

Sorry if this is a basic question, but how can I keep a button in the :active state after clicking? In case it's relevant, I have a sidebar with 5 buttons. Four of them trigger the appearance of one div while hiding the others, and the fifth button f ...

Display identical elements from an array and shuffle them every 300 seconds

I created this code snippet that currently displays 5 random rows of data from an array each time it is executed. My goal is to modify the code so that it selects and displays the same 5 random values from the array for a duration of 5 minutes before rand ...

What is the process for implementing Devexpress themes on a simple HTML table?

Incorporating Devexpress's MVC extensions into my MVC3 w/razor project has been a smooth experience so far. I currently have data grids using Devexpress's MVC extensions, alongside basic HTML tables that lack any styling. Is there a method to im ...

Implementing a method in MVC using .NET Core

As a newcomer to MVC, I am facing a challenge with my app. It features a list of links to websites, and I want to increment the "usage" integer each time a link is clicked. public class Link { public int ID { get; set; } [Required] ...

Adjusting the initial date on the Datepicker

I am currently working on developing a calendar using bootstrap datepicker that should enable users to select a day starting 24 hours from the current date. I came across a similar query posted on Stack Overflow in the past, but the suggested solution isn& ...

Thymeleaf allows for the splitting of tables across different pages when generating a PDF document

I have a custom HTML template containing a table structure <table id="people" border="1"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Salary</th> </ ...

Ways to adjust the background color

Is there a way to change the background color instead of font color in this code snippet? def cloud_height_style_function(vals): return pd.cut(vals,[-np.inf,199,499,999,3000, np.inf], # need to review the bin a bit labels=[f'color: ...

Clicking "Submit" button in JQuery dialog does not activate the __doPostBack function

I am facing an issue with a textbox in a JQuery popup dialog. The Keypress event on the textbox is functioning correctly and only captures the enter key. However, I am trying to trigger __doPostBack on the enter key of the textbox but have been unsuccessfu ...

Leverage jquery-ui for enhanced functionality in portal version 8

After successfully implementing jQuery in Websphere Portal 8 by following this article, I now have a new question. How can I incorporate jQuery-UI into Websphere Portal 8? My concern is that jQuery-UI comes with multiple JS and CSS files, so I am unsure ...

Divide the canvas into 100 separate sections using Javascript

Help! I'm trying to divide a canvas into 100 squares that are 50x50px each, but my current code is becoming too lengthy with multiple for loops. Is there a more efficient way to achieve this with just one for loop? https://i.sstatic.net/0UD0s.png Bel ...

Update the URL using JQuery and Ajax without having to reload the page, ensuring compatibility with Internet Explorer versions 8 and 9

Upon the initial loading of my webpage, it directs to the following URL: /default/ After clicking the "nextPost" button on the screen (which includes an attribute named data-nextPostNumber), the corresponding code is as follows: event.preventDefault(); ...

Displaying array elements on a webpage using JavaScript in HTML

Looking to display multiple blocks in HTML using a JavaScript array. The array contains names such as: var name=['amit','mayank','jatin'];. I need to repeat a certain portion of code in order to show the elements of the array, ...

What is the best way to replace a removed <div> element with a left or right positioned <div>?

In my layout, I have 3 columns positioned next to each other: one on the left as the left modules panel, one in the center as the content column, and one on the right as the right modules panel. This is how it's styled using CSS: #left{ width: 2 ...

JavaScript problem with hovering action causing additional buttons to appear

Currently, I am developing a user interface where, upon hovering over an LI element, 2 buttons appear to provide additional functionality - "edit" and "remove". However, I am facing challenges with the mouse hit zones. The mouseover function works effect ...