删除HTML标记的属性 [英] Remove attribute of HTML tag

查看:98
本文介绍了删除HTML标记的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以删除第一个HTML < div> 标记的属性?所以,这个:

Is it possible to remove the attribute of the first HTML <div> tag? So, this:

<div style="display: none; ">aaa</div>

变为

<div>aaa</div>

来自以下内容:

<div style="display: none; ">aaa</div>
<a href="#" style="display: none; ">(bbb)</a>
<span style="display: none; ">ccc</span>​


推荐答案

要从字面上删除第一个元素,请使用 .removeAttr()

To remvove it from literally the first element use .removeAttr():

$(":first").removeAttr("style");

或在这种情况下 .show() 将通过删除 display 属性来显示该元素:

or in this case .show() will show the element by removing the display property:

$(":first").show();






虽然你可能想把它缩小到里面别的东西,例如:


Though you probably want to narrow it down to inside something else, for example:

$("#container :first").removeAttr("style");

如果要显示第一个隐藏的,请使用 :隐藏 作为您的选择器:

If you want to show the first hidden one, use :hidden as your selector:

$(":hidden:first").show();

这篇关于删除HTML标记的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆