How do I change the class of several tds when hovering over one of them?

NickEckhart

here's my problem. I have a month-view type calendar in a table. In this calendar there can be certain periods which are (they have the class 'blocked'). The first date of such a period has the class 'blocked' as well as 'start', while the last date has the classes 'blocked' and 'end'.

Now, when I hover over one of these TDs I want that td, and all the other ones in ONLY THAT SPECIFIC period (can be over multiple rows), to get the class 'blocked-highlight'.

Here is a JSFiddle which generally shows what I have: http://jsfiddle.net/aoxmpouw/

Here is the Code from the Fiddle:

RELEVANT PART OF HTML:

        ...     
        <td>13</td>
        <td>14</td>
    </tr>
    <tr>
        <td>15</td>
        <td>16</td>
        <td class="blocked start">17</td>
        <td class="blocked">18</td>
        <td class="blocked">19</td>
        <td class="blocked">20</td>
        <td class="blocked">21</td>
    </tr>
    <tr>
        <td class="blocked">22</td>
        <td class="blocked">23</td>
        <td class="blocked end">24</td>
        <td>25</td>
        <td>26</td>
        <td>27</td>
        ...

JS:

$( document ).ready(function() {
    $("td.blocked").hover(
        function() {
            $( this ).addClass('blocked-highlight')
        }, function() {
            $( this ).removeClass('blocked-highlight')
        }
    );
});

CSS:

.blocked {
    color: white;
    background-color: red;
}

.start {
    border-left: 5px solid black;
}

.end {
    border-right: 5px solid black;
}

.blocked-highlight {
    background-color: blue;
}

JQuery is perfectly fine, as well as pure CSS solutions, if there are any.

Thanks in advance, Cheers -N

Jeroen

If you have multiple periods / blocks and they are generated dynamically. give them a shared attribute or class. Then you could do something like:

HTML:

   ...     
    <td>13</td>
    <td>14</td>
</tr>
<tr>
    <td>15</td>
    <td>16</td>
    <td class="blocked start" rel="1">17</td>
    <td class="blocked" rel="1">18</td>
    <td class="blocked" rel="1">19</td>
    <td class="blocked" rel="1">20</td>
    <td class="blocked" rel="1">21</td>
</tr>
<tr>
    <td class="blocked" rel="1">22</td>
    <td class="blocked" rel="1">23</td>
    <td class="blocked end" rel="1">24</td>
    <td>25</td>
    <td>26</td>
    <td>27</td>
    ...

JS:

   $( document ).ready(function() {
      $("td.blocked").hover(
       function() {
        rel = $(this).attr('rel');
        $( "td[rel='"+rel+"']").addClass('blocked-highlight');
       }, function() {
        rel = $(this).attr('rel');
        $( "td[rel='"+rel+"']").removeClass('blocked-highlight');            
       }
    );
});

Demo: http://jsfiddle.net/aoxmpouw/5/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I change the class of several tds when hovering over one of them?

From Dev

How to change css of one class when hovering over another?

From Dev

In Labview how can I change the mouse pointer when hovering over one of my boolean controls?

From Dev

How do I remove the space when hovering over a nav link?

From Dev

How do I remove the zoom icon that appears when hovering over image?

From Dev

How do I show a sign up/log in field when hovering over it

From Dev

How do I trigger a click when hovering over a element for x seconds, using JQuery?

From Dev

Change class of other div when hovering on one div

From Dev

how to make color change to white when hovering over button

From Dev

How do I change the color of one vertex instead of all of them?

From Dev

How to highlight multiple rows when hovering over one row

From Dev

How can I change element while hovering over another?

From Dev

How can I avoid CSS flickering when hovering over areas?

From Dev

How can I avoid CSS flickering when hovering over areas?

From Dev

How can I get only the specific H3 I am hovering over to show and not all of them?

From Dev

Why does the <li> element not change color and width when I hover the mouse over it after hovering over the image?

From Dev

Change image color when hovering over li

From Dev

Change image when hovering over a list of text

From Dev

Overlapping Anchor Tags When Hovering Over One

From Dev

How do I to run multiple applications and manage them over SSH on one Ubuntu Server?

From Dev

How do I combine several images into one?

From Dev

How do I combine several programs into one?

From Dev

How to shift several buttons when mouse enter over another one

From Dev

Change css class when hovering html element

From Dev

How to I make one row/segment of a table change when I hover over another row/segment?

From Dev

In chrome, when in youtube, and I change the windows volume, play buttons appear. How do I remove them?

From Dev

When using custom cursors, how can you set the I-bar cursor when hovering over text?

From Dev

CSS how to select each li after the one im hovering, IF i hover over a specific child of that li

From Dev

change opacity of one div by hovering over another div

Related Related

  1. 1

    How do I change the class of several tds when hovering over one of them?

  2. 2

    How to change css of one class when hovering over another?

  3. 3

    In Labview how can I change the mouse pointer when hovering over one of my boolean controls?

  4. 4

    How do I remove the space when hovering over a nav link?

  5. 5

    How do I remove the zoom icon that appears when hovering over image?

  6. 6

    How do I show a sign up/log in field when hovering over it

  7. 7

    How do I trigger a click when hovering over a element for x seconds, using JQuery?

  8. 8

    Change class of other div when hovering on one div

  9. 9

    how to make color change to white when hovering over button

  10. 10

    How do I change the color of one vertex instead of all of them?

  11. 11

    How to highlight multiple rows when hovering over one row

  12. 12

    How can I change element while hovering over another?

  13. 13

    How can I avoid CSS flickering when hovering over areas?

  14. 14

    How can I avoid CSS flickering when hovering over areas?

  15. 15

    How can I get only the specific H3 I am hovering over to show and not all of them?

  16. 16

    Why does the <li> element not change color and width when I hover the mouse over it after hovering over the image?

  17. 17

    Change image color when hovering over li

  18. 18

    Change image when hovering over a list of text

  19. 19

    Overlapping Anchor Tags When Hovering Over One

  20. 20

    How do I to run multiple applications and manage them over SSH on one Ubuntu Server?

  21. 21

    How do I combine several images into one?

  22. 22

    How do I combine several programs into one?

  23. 23

    How to shift several buttons when mouse enter over another one

  24. 24

    Change css class when hovering html element

  25. 25

    How to I make one row/segment of a table change when I hover over another row/segment?

  26. 26

    In chrome, when in youtube, and I change the windows volume, play buttons appear. How do I remove them?

  27. 27

    When using custom cursors, how can you set the I-bar cursor when hovering over text?

  28. 28

    CSS how to select each li after the one im hovering, IF i hover over a specific child of that li

  29. 29

    change opacity of one div by hovering over another div

HotTag

Archive