父属性名称值的每个绑定文本上的jquery

父属性名称值的每个绑定文本上的jquery,jquery,Jquery,我正在尝试执行我自己的工具提示,它应该显示父元素名称值的值: 我在锚标记后追加新的div,并尝试绑定父锚名称值的文本值 但是在我所有的.tooltipContainer div中,我只得到姓氏valuetooltip 3333?谁能帮助解决这个问题 HTML: <!-- tooltip - begin --> <ul> <li><a name="tooltip 111111

我正在尝试执行我自己的工具提示,它应该显示父元素名称值的值:

我在锚标记后追加新的div,并尝试绑定父锚名称值的文本值

但是在我所有的.tooltipContainer div中,我只得到姓氏valuetooltip 3333?谁能帮助解决这个问题

HTML:
            <!-- tooltip - begin  -->
            <ul>
                <li><a name="tooltip 1111111111111" class="customToolTip">tool tip 1111</a></li>
                <li><a name="tooltip 2222222222222" class="customToolTip">tool tip 222</a></li>
                <li><a name="tooltip 3333333333333" class="customToolTip">tool tip 333333</a></li>
            </ul>
            <!-- tooltip  end  -->  

    JS:
    $(document).ready( function() { 
        $(".customToolTip").each(function(i){
            var customToolTipName = $(this).attr('name');
            var parentAttrNameValue = $(this).parent().find(".customToolTip").attr('name');
        //  alert(parentAttrNameValue);

            $(this).after('<div class="tooltipContainer"></div>');
            $(".tooltipContainer").html(parentAttrNameValue);
        });
    }); 
问题是$.tooltipContainer,它使用类tooltipContainer(而不是刚刚添加的)获取所有元素,并将其html设置为parentAttrNameValue值,因此在处理最后一项时,将为所有元素设置其值

相反,您可以添加如下所示的元素,这里我们在创建新元素时为其设置html

$(document).ready(function () {
    $(".customToolTip").each(function (i) {
        var customToolTipName = $(this).attr('name');
        var parentAttrNameValue = $(this).parent().find(".customToolTip").attr('name');
        //  alert(parentAttrNameValue);

        $('<div />', {
            html: parentAttrNameValue, 'class': 'tooltipContainer'
        }).insertAfter(this);
    });
});
演示:


还不确定什么是parentAttrNameValue,它与customToolTipName相同

ya parentAttrNameValue和customToolTipName相同。。。谢谢你的代码。。。如何将此作为方法保存。。这样我们就可以用于任何项目?