需要从锚标记中删除目标属性,然后才能将其添加到 TD 以上

Man*_*ngh 0 jquery

我正在使用 HTML 和 Jquery

下面是TD的 html 代码,它在匹配LI HTML 代码下方的ID后附加

<td style="border-top-style: solid; border-right-style: solid; border-left-style: solid;
                    border-bottom-style: solid" id="Physical">
                    Physical Science Course
                </td>

    <li id="PhysicalTooltip"><a href="#" target="_blank" class="toolTip">
        <img src="/images/q_mark.gif" alt="" /><span style="width: 300px; padding: 10px 10px 10px 55px;">Testing
            Physical.</span></a> </li>
Run Code Online (Sandbox Code Playgroud)

这是匹配相关 ID 并从 LI 上方获取标签并进一步追加到 TD 上方的 Jquery

$(document).ready(function() 
            {

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

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

                        //alert($tooltip);

                        // append it to the current cell
                        $(this).append($tooltip);

                    });
            });
Run Code Online (Sandbox Code Playgroud)

现在我想在它被附加到 TD 以上之前删除我的目标属性。

请建议!

tva*_*son 5

您需要在列表元素内找到锚点并使用 removeAttr。

$tooltip.find('a').removeAttr('target');
Run Code Online (Sandbox Code Playgroud)