What are some strategies for making mouseover content stand out in my timeline?

I am currently working on a project involving a small timeline that utilizes the hover function in jQuery. I've encountered an issue where duplicating list items causes the hovers to no longer function individually, as they are controlled by the duplicated classes. Does anyone have any suggestions on how I can differentiate these hovers so that they remain independent?

If you'd like to see the issue firsthand, you can check out the JSFIDDLE http://jsfiddle.net/Jason1975/6nwkd2c8/10/.

Any guidance or help would be greatly appreciated.

HTML CODE

 <div id="container">
 <ul id="new">
 <!-- Block Up Date on top -->
 <li class="block-up">
    <p class="date-up"><a href="" id="1">24 January 2015</a></p>
    <p class="event-up">This event happend on this date</p>
 </li>
 <!-- Block Down Date at the bottom -->
 <li class="block-down">
    <p class="event-down">This event happend on this date</p>
    <p class="date-down"><a href="" >24 February 2015</a></p>
 </li>
 <!-- Block Up Date on top -->
 <li class="block-up">
    <p class="date-up"><a href="">24 January 2015</a></p>
    <p class="event-up">This event happend on this date</p>
 </li>
 <!-- Block Down Date at the bottom -->
 <li class="block-down">
    <p class="event-down">This event happend on this date</p>
    <p class="date-down"><a href="">24 February 2015</a></p>
 </li>
 </ul>
</div>

JQUERY

 <script src="js/jquery_1-11.js" type="text/javascript"></script>
 <script type="text/javascript">
 <!--the toggle-->
 $(document).ready(function() {
 $(".block-up a").hover(function(){
 $(".event-up").css('visibility', 'visible');
 },
 function() {
 $(".event-up").css('visibility', 'hidden');
 });
 $(".block-down a").hover(function(){
 $(".event-down").css('visibility', 'visible');
 },
 function() {
 $(".event-down").css('visibility', 'hidden');
 });
 });
 </script>

CSS

 a  { font-size: 14px; text-decoration: none; color: #666666; }
 a:hover    { font-size: 14px; color: #F47C00;  }
 /* Timeline */
 #container {   width: 800px;
            height: 80px;
            margin: 0 auto;
            overflow: hidden;
            white-space:nowrap;
            background:url(../images/line.png) center 50% repeat-x;
 }
 ul#new {  display: inline;  }
.block-up   {   position: relative;
            display: inline-block;
            list-style:none;
            width: 200px;
            height: 80px;
            margin: 0!important;
            top: 0;
            background: url(../images/dot.png) center 50% no-repeat;
 }
 .block-down {  position: relative;
            display: inline-block;
            list-style:none;
            width: 200px;
            height: 80px;
            margin: 0!important;
            top: 0;
            background: url(../images/dot.png) center 50% no-repeat;
 }
 .block-down a  { font-size: 14px; }
 .block-down a:hover    { font-size: 14px; }
 .date-up {         padding-bottom: 20px;
            text-align:center;
 }
 .event-up {    padding-top: 20px;
            text-align: center;
            font-size: 14px;
            color: #F47C00;
            visibility: hidden;
  }
 .date-down {   padding-top: 20px;
            text-align:center;
 }
 .event-down {  padding-bottom: 20px;
            text-align: center;
            font-size: 14px;
            color: #F47C00;
            visibility:hidden;
  }

Answer №1

If you're looking for a solution, check out this example:

$(document).ready(function() {
$(".block-up a").hover(function(){
$(this).parent().parent().find(".event-up").css('visibility', 'visible');
},
function() {
$(".event-up").css('visibility', 'hidden');
});
$(".block-down a").hover(function(){
$(this).parent().parent().find(".event-down").css('visibility', 'visible');
},
function() {
$(".event-down").css('visibility', 'hidden');
});
});

Answer №2

If you're looking for a solution, check out this helpful link.

$(function() {
    function detectElement(el) {
        return el.className.indexOf('up') >= 0 ? $(el).next() : $(el).prev();    
    }
    $('.date-down, .date-up').hover(function(){
        detectElement(this).css('visibility', 'visible');
    }, function(){
        detectElement(this).css('visibility', 'hidden');
    })    
});

Alternatively, consider assigning common classes to the up and down blocks like block, event, date. Then, utilize these classes to manage their behavior more efficiently.

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

Submitting forms using Ajax

Utilizing AJAX to submit an HTML input form and redirecting the output page upon completion has presented me with some unexpected results. I have explored two different approaches, but for some reason, they yield different outcomes. The HTML form structur ...

The text field is being styled with inline styles automatically

I am trying to set a custom width for a textarea in my form, but the inline styles are automatically overriding my CSS. I have checked my scripts, but I am unsure which one is manipulating the DOM. If you have any insight, please let me know. This is the ...

My code operates successfully only on the initial execution

I am encountering an issue with my function regarding a login form validation using JSON data. The code seems to be working correctly, but only when I input the correct data immediately after refreshing the page. For example, if I enter an incorrect login/ ...

What steps can I take to bring this idea to life in my gallery?

Currently, I am facing a roadblock while transitioning my design concept into actual code. My main concern lies with creating this art piece. Although the gallery is up and running with all the images in place, I'm encountering difficulties with the s ...

Shift the <tfoot> table to the right using CSS

Is there a way to shift the red area (x1, x2) to the right using only CSS in a table where the <tfoot> tag cannot be edited? https://jsfiddle.net/qL03728p/ table { width: 100%; border-collapse: separate; } table td { border-top: 1px solid ...

A method for automatically refreshing a webpage once it switches between specific resolutions

On my page www.redpeppermedia.in/tc24_beta/, it functions well at a resolution of over 980px. However, when the resolution is brought down to 768px, the CSS and media queries alter the layout. But upon refreshing the page at 768px, everything corrects itse ...

Refreshing Page Following Ajax Submission

Currently, I am working on a Single Page Application using asp.net MVC. When I make a post request to the server using Ajax, the Web API performs parameter validation and then returns a Json String. The code snippet for the Web API function is shown below ...

Issue with integrating Twitter Bootstrap JavaScript components (tabs, popups, dropdowns) in Drupal causing malfunction

After successfully designing the site and converting it into HTML using Twitter Bootstrap, everything seemed to be working perfectly in the static model. However, once I handed over the HTML to developers for implementation of dynamic code and template c ...

What is the best way to crop and edit a picture, incorporating rounded edges and a unique perspective?

Is there a way to create a unique design using HTML and CSS, where a div contains an image that is clipped and masked to achieve a specific look? Here's an example of what I'm aiming for: https://i.sstatic.net/nmDCp.png I've spent the past ...

What is the process for including icons on buttons?

I have been researching how to use Font Awesome software to incorporate icons into my HTML elements, but I am uncertain about the implementation process for my specific case. Currently, I have created a basic webpage with buttons and I would like to includ ...

When focusing on a textfield, the background remains the same color and does not change

Hey there! I have a question about changing background color when clicking on a text field. I followed the code below but it doesn't seem to be working for me. Can someone help me figure out what's wrong? //jQuery $(function() { $('inp ...

Position validation in jQuery is crucial for ensuring that form

After attempting to implement the jquery validate plugin by following the example provided at http://docs.jquery.com/Plugins/Validation, I have encountered some challenges in my own code. The issue lies in determining where to call the validation function. ...

SQL/PHP challenge: Trouble updating a record

As a newcomer to PHP, I apologize if my question is basic. I am attempting to update a record using PHP / SQL. Despite researching the error message online, I cannot pinpoint the issue within my code: An error occurred: SQLSTATE[HY093]: Invalid paramet ...

The alignment of the elements within the jumbotron is off

Hey there! I'm currently struggling to align the jumbotron with my calendar icon. Unfortunately, the elements of the jumbotron are not lining up properly. Could someone lend a hand in guiding me through this issue? Any ideas would be greatly appreciat ...

Adjusting AJAX Parameters with Form.serialize() Before Sending Using jQuery

When a button is clicked, I have a jQuery.ajax() POST request that has its $(this).parents('form').serialize() set as the data parameter. The form contains a Textarea with a default placeholder text that I want to replace with a blank value just ...

What are some ways to customize the appearance of Skype for Business HTML messages when integrating with the Bot Framework?

Recently, I created a bot using Microsoft's bot framework and I've noticed that while it supports sending HTML messages, the CSS styling doesn't seem to work. As a result, the HTML messages appear quite bland and I'm really eager to add ...

Chrome extension causing delays in rendering HTML on webpage

Currently, I am developing a script (extension) that targets a specific HTML tag and performs certain actions on it. The challenge I am facing is that this particular HTML tag gets dynamically loaded onto the page at a certain point in time, and I need to ...

Use a jQuery or XPath selector to choose certain HTML tags from a list of HTML tags

Consider this html structure : ... <div class="a">April 2018</div> <div class="b">Monday 02</div> <div class="c">...</div> <!-- Capture this tag and its children --> <div class="c">...</div> <!-- ...

Tips for navigating through a JSON response to find specific information:

I'm currently looking for a way to search within a JSON result that has been returned. The result that was returned looks like this: {"Result":["Css","java","jquery","asp.net","mvc","javascript","asp","c#"]} My goal is to extract all the words that ...

What is the best way to apply a datepicker to all textboxes with a specific class using jQuery?

I have enclosed multiple fields within div elements in order to specify them with a datepicker for a better user experience. For example: <div class="need-date" > <label>Appointment Date</label> <input id="id_appointment_date" ty ...