从body的所有子元素中删除属性(Remove an attribute from all the children elements of body)

编程入门 行业动态 更新时间:2024-10-28 02:21:31
从body的所有子元素中删除属性(Remove an attribute from all the children elements of body)

我正在使用bing的脚本。 好吧,当我运行它时,它会为所有元素分配一个属性“lang”并改变我自己的样式。 该脚本在线,所以我无法编辑它。 我能做的是使用jquery从所有元素中删除该属性,因此不会发生样式更改。 这是我搜索后到目前为止所尝试的内容。

$('body').children("*").removeAttr('lang'); $('body').find("*").removeAttr("lang");

他们没有工作。 有什么建议吗?

i am using a script from bing. Well, when i run it, it assigns an attribute "lang" to all of the elements and changing my own styling. The script is online so i can't edit it. What i can do is remove that attribute from all the elements using jquery so no styling change would occur. This is what i have tried so far after searching through.

$('body').children("*").removeAttr('lang'); $('body').find("*").removeAttr("lang");

They are not working. Any suggestion?

最满意答案

尝试这个

$('* [lang]').removeAttr('lang');

DEMO

要么

$('[lang]').removeAttr('lang');

DEMO

You can use Has Attribute Selector [name] and then use removeAttr()

Selects elements that have the specified attribute, with any value.

$('[lang]').removeAttr('lang');

console.log($('span').prop('outerHTML')) 
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span lang='en'>1</span> 
  
 

更多推荐

本文发布于:2023-08-01 13:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1359358.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   元素   body   Remove   elements

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!