Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.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附加html标记_Javascript_Jquery - Fatal编程技术网

使用javascript或jquery附加html标记

使用javascript或jquery附加html标记,javascript,jquery,Javascript,Jquery,我想在之后添加一些文本。以下html来自我的内容页 <section id="header-title" style="margin-bottom: 0;"> <div class="container"> <div class="row"> <h2 style="text-align: left;">Create User</h2> </di

我想在
之后添加
一些文本。以下
html
来自我的内容页

<section id="header-title" style="margin-bottom: 0;">
       <div class="container">
           <div class="row">
               <h2 style="text-align: left;">Create User</h2>
           </div>
      </div>
</section>

创建用户
如何使用javascript和jquery附加
html标记

试试

$('#header-title div.row').append('<span></span>');
$(“#标题div.row”).append(“”);
或者更具体地说

$('<span></span>').insertAfter($('#header-title').find("h2:contains('Create User')"));
$('').insertAfter($('#标题').find(“h2:contains('Create User'))));
您可以使用:

$('#header-title .row').append('<span />');
$('#header title.row')。追加('');

jQuery:

$(“”)之后插入(“h2”)

尝试以下操作:

$('<span />', { text: 'Some text' }).insertAfter('h2');
$('',{text:'Some text'}).insertAfter('h2');
这将保证
span
始终位于
h2
下方。使用
元素上的
append
将其作为
div
中的最后一个元素,该元素可能并不总是在
h2
之后

 $("#header-title").find("h2").after($("<span/>", {
    text: "text here"
}));
$(“#标题”)。查找(“h2”)。在($(“”)之后{
文本:“此处文本”
}));
你喜欢这样吗

 $( ".row h2" ).append( "<span>Test</span>" );
$(“.row h2”)。追加(“测试”);
试试这个:

   $('#header-title').find('.row').append($('<span>'))
$('#标题')。查找('.row')。追加($('')

这将把
span
插入
h2
Nope<代码>“我想在”
后追加一个“
修复了它。不管怎样,这个问题现在越来越拥挤了。