选择器返回的是类似数组的结构,使用 id 选择器的时候,只会返回一个元素,但是还是会使用类似数组的结构的。观察这个结构对象的原型方法
遍历获得的元素:
Array.from($("div")).forEach((value) => { | |
console.log(value); | |
console.log($(value)); | |
}) |
在 $()
中传入 dom 元素对象,可以得到 jq 对象。
// 选中同时具有类名 one 和类名 two 的元素 | |
$(".one.two").css({ | |
width: '200px', | |
'height': '200px', | |
'background-color': 'blue', | |
'margin': '20px', | |
}) |