jQuery [attribute]选择器

[attribute]选择器语法

$('[attribute]')

[attribute]选择器语法解析

jQuery中的[attribute]选择器,可以用于选择所有包含attribute属性的HTML元素。

[attribute]选择器实例代码

下方实例,通过[attribute]选择器选择所有包含width属性的元素,注意区别style属性中的width和元素本身具备的width属性,比如下方的两个img分别使用这两种width设置了宽度,但只有使用元素的width属性的img才会被选择:

<img src="../../static/img/test.png" style="width:50%;height:50px;">
<br><br>
<img src="../../static/img/test.png" width="50%" height="50">
<br><br>
<button id="test">确定</button>

<script>
$("#test").click(function(){
  $("[width]").css("height","100")
})
</script>

免责声明:内容仅供参考,不保证正确性!


全栈前端 / jQuery教程 :






Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.