简体   繁体   English

从脚本标签中找到特定的数据属性并删除脚本标签

[英]Find particular data attribute from script tag and remove the script tag

I have some script tags in my html page. 我的html页面中有一些脚本标签。 My question is how to remove particular data attribute from script tag 我的问题是如何从脚本标记中删除特定的数据属性

<script src="js/scripttest1" data-invalid= "true" type="text/javascript"></script>
<script src="js/scripttest2" data-invalid= "true" type="text/javascript"></script>
<script src="js/scripttest3" data-required= "true" type="text/javascript"></script>

I want remove the data attribure 'data-invalid' in jquery on dom ready please help me regarding on this. 我想在DOM上的jquery中删除数据属性'data-invalid',请对此提供帮助。

I tried: 我试过了:

$("script['data-invalid']").remove();

it not working please give proper solution how to solve this issue. 如果无法正常工作,请提供适当的解决方案以解决此问题。

You need removeAttr() 您需要removeAttr()

$("script").removeAttr('data-invalid');

Update 更新

No i want script tag should be removed not the attribute 不,我要删除脚本标签而不是属性

If you want to remove the script tag itself, do 如果要删除脚本标签本身,请执行

$("script[data-invalid]").remove();

without the single quotes 没有单引号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM