gpt4 book ai didi

javascript - 从所有 HTML 元素中移除属性 title

转载 作者:太空宇宙 更新时间:2023-11-04 13:35:46 25 4
gpt4 key购买 nike

我想完全删除 html 文档中所有元素的 title 属性。来自表格、p、img、div 等。

目前我这样做:

$(document).ready(function(){
$("a").removeAttr("title");
$("img").removeAttr("title");
$("div").removeAttr("title");
// and so on
// and so on
// and so on
});

有没有更优雅的方法来做到这一点?不选择单个元素?

最佳答案

使用属性选择器,只选择具有 title 属性的元素,而不是所有元素。

$("[title]").removeAttr("title");

关于javascript - 从所有 HTML 元素中移除属性 title,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39081582/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com