How to add a hint by matching identifiers in HTML using jQuery

I use HTML and jQuery

I have a problem below, I have the code below

<table style="border-top-style: solid; border-right-style: solid; border-left-style: solid;
    border-bottom-style: solid" cellspacing="1" cellpadding="1" width="100%" border="1">
    <tbody>
        <tr>
            <td style="border-top-style: solid; border-right-style: solid; border-left-style: solid;
                background-color: #dfdfdf; text-align: left; border-bottom-style: solid" align="left">
                <strong>Type of Course</strong>
            </td>
            <td style="border-top-style: solid; border-right-style: solid; border-left-style: solid;
                background-color: #dfdfdf; text-align: left; border-bottom-style: solid" align="left">
                <strong>Courses </strong>
            </td>
            <td style="border-top-style: solid; border-right-style: solid; border-left-style: solid;
                background-color: #dfdfdf; text-align: left; border-bottom-style: solid" align="left">
                <strong>Credits</strong>
            </td>
        </tr>
        <tr>
            <td style="border-top-style: solid; border-right-style: solid; border-left-style: solid;
                background-color: #dfdfdf; border-bottom-style: solid">
                Core
            </td>
            <td style="border-top-style: solid; border-right-style: solid; border-left-style: solid;
                border-bottom-style: solid" id="Communication">
                Communication Course
            </td>
            <td style="border-top-style: solid; border-right-style: solid; border-left-style: solid;
                border-bottom-style: solid">
                5
            </td>
        </tr>
        <tr>
            <td style="border-top-style: solid; border-right-style: solid; border-left-style: solid;
                border-bottom-style: solid">
            </td>
            <td style="border-top-style: solid; border-right-style: solid; border-left-style: solid;
                border-bottom-style: solid">
                English Course
            </td>
            <td style="border-top-style: solid; border-right-style: solid; border-left-style: solid;
                border-bottom-style: solid">
                5
            </td>
        </tr>
        <tr>
            <td style="border-top-style: solid; border-right-style: solid; border-left-style: solid;
                border-bottom-style: solid">
            </td>
            <td style="border-top-style: solid; border-right-style: solid; border-left-style: solid;
                border-bottom-style: solid" id="Mathematics">
                Mathematics Course
            </td>
            <td style="border-top-style: solid; border-right-style: solid; border-left-style: solid;
                border-bottom-style: solid">
                5
            </td>
        </tr>
    </tbody>
</table>

<div style="display: none">
    <ul>
        <li id="CommunicationTooltip">
            <a href="#" class="toolTip">
                <img src="/images/q_mark.gif" alt=""/><span style="width: 500px;">Testing Communication.</span>
            </a>
        </li>
        <li id="MathematicsTooltip">
            <a href="#" class="toolTip">
                <img src="/images/q_mark.gif" alt=""/><span style="width: 500px;">Testing Mathematics.</span>
            </a>
        </li>
    </ul>
</div>  

In the above HTML, you will see that we have many TDs , some without IDs , and some TDs have IDs , and below you see that I have a DIV with LI with ID , as TD indicated above with an additional hint in it.

, ID (TD LI), Tooltip, A HREF TD, HTML TD

   <td style="border-top-style: solid; border-right-style: solid; border-left-style: solid;
        border-bottom-style: solid" id="Communication">
        Communication Course 
<a href="#" class="toolTip">
        <img src="/images/q_mark.gif" alt=""/><span style="width: 500px;">Testing Communication.</span>
    </a>
    </td>

, JQuery

+3
1

, :

$(document).ready(function() {

    // bind to cells with an ID attribute
    $("table > tbody > tr > td[id]").mouseover(function() {

        // grab the anchor from the LI whose ID starts with the cell ID
        var $tooltip = $("div:hidden li[id^=" + $(this).attr("id") + "] a");

        // append it to the current cell
        $(this).append($tooltip);
    }).mouseout(function() {

        // remove the anchor/tooltip
        $(this).find("a").remove();
    });
});
+3

Source: https://habr.com/ru/post/1733908/


All Articles