Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将带有jQuery的链接中的标题内容写入相应链接后的DOM中_Javascript_Html_Jquery_Each - Fatal编程技术网

Javascript 将带有jQuery的链接中的标题内容写入相应链接后的DOM中

Javascript 将带有jQuery的链接中的标题内容写入相应链接后的DOM中,javascript,html,jquery,each,Javascript,Html,Jquery,Each,我将捕获链接标题并在 这是我的DOM标记: 到目前为止没有问题: $( "a.sidenote-icon" ).wrapAll( "<span class='sidenote'><cite class='icon quelle'></cite></span>" ); var title = $( "a.sidenote-icon" ).attr('title');

我将捕获链接标题并在

这是我的DOM标记:

到目前为止没有问题:

    $( "a.sidenote-icon" ).wrapAll( "<span class='sidenote'><cite class='icon quelle'></cite></span>" );

    var title = $( "a.sidenote-icon" ).attr('title');
    var titlewrap = "<span>" + title + "</span>";
    $( "cite" ).after(titlewrap);
$(“a.sidenote-icon”).wrapAll(“”);
var title=$(“a.sidenote-icon”).attr('title');
var titlewrap=“”+title+”;
$(“引用”)。在(标题栏)之后;
如果我在几个案例中使用each函数,jQuery会将标题添加到一个范围中,但会添加三次,因为我的段落中有三个链接。下面是我对每个函数的看法

$( "a.sidenote-icon" ).each(function() {
    $( this ).wrapAll( "<span class='sidenote'><cite class='icon quelle'></cite></span>" );
    var title = $( this ).attr('title');
    var titlewrap = "<span class='testy'>" + title + "</span>";
    $( "cite" ).after(titlewrap);
});
$(“a.sidenote-icon”)。每个(函数(){
$(此).wrapAll(“”);
var title=$(this.attr('title');
var titlewrap=“”+title+”;
$(“引用”)。在(标题栏)之后;
});
我对每个函数都有问题。标题应该只插入一次-对于我的页面上与特殊类的每个链接。我的错误在哪里?查看输出

请检查更新的

多亏了。

$(“a.sidenote-icon”)。每个(函数(){
$(此).wrapAll(“”);
var title=$(this.attr('title');
var titlewrap=“”+title+”;
$(this.parent())(titlewrap)之后;
});

请提供问题的正确答案。抱歉:
$(“引用”)
每次选择所有
引用
元素,您需要将其限制为正确的元素。请尝试
$(this).parent()。在(titlewrap)之后开始,然后遍历到父级。非常感谢。嗨,但我需要所有的链接与这种效果,不仅是第一个。我的问题是,标题在
cite
-标记后写了三次。
$( ".frame a.sidenote-icon:first" ).each(function() {
    $( this ).wrapAll( "<span class='sidenote'><cite class='icon quelle'></cite></span>" );

    var title = $( this ).attr('title');
    var titlewrap = "<span class='testy'>" + title + "</span>";
    $( "cite" ).after(titlewrap);

});
$( ".frame a.sidenote-icon:first" ).
$( "a.sidenote-icon" ).each(function() {
    $( this ).wrapAll( "<span class='sidenote'><cite class='icon quelle'></cite></span>" );

    var title = $( this ).attr('title');
    var titlewrap = "<span class='testy'>" + title + "</span>";
    $( this ).parent().after(titlewrap);
});