Jquery在页面上查找第一个h1并将更多html append 到其html中

标签 jquery html append

如何在页面上找到第一个 h1 并将更多 html append 到其 html 中?我正在尝试这样的事情,但它给了我错误 -

 var str = $('h1:first').html();
    $('h1:first').html(str.append('some more html '));

最佳答案

<强> .html() 可以将函数作为参数,并从中返回当前html并添加新的 html.

$('h1:first').html(function(){
  return $(this).html() + ' some more html';
});

关于Jquery在页面上查找第一个h1并将更多html append 到其html中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35879554/

相关文章:

jquery - 如何遍历 AngularJS 中元素的所有属性(css、attr)?

jQuery 过滤函数 $(this).has()

php echo html - margin-left 不工作

javascript - 按循环内的条件更改 append 的 td

javascript - 如何打开弹出浏览器窗口以包含主页的持续更新?

jquery - ASP.Net/Jquery 在 Response.End() 之后查找客户端事件

html - 在 CSS 中使用重复图像渲染草地

javascript - 如何强制 div 在浏览器调整大小时重绘?

shell - 如何将 shell 脚本的所有输出写入单个新文件

python - 为什么我的列表在我尝试 append 它们时没有加入 Python