我的页面有六个 div
元素。
使用 jQuery 和 Z-Index,单击按钮会增加一个 div
的宽度以覆盖所有其他部分。在此过程中,它还假定该类:active
(z-index:900)。
当我单击另一个按钮时,具有 active
类的 div
应返回到其原始大小和位置。原始值保存到变量中,但我如何知道 active
类的元素名称?
最佳答案
这是 jQuery
function 的基本特征之一又名 $()
.
这样做:
var elements = $(".myclass");
将为您提供所有使用CSS类myclass
的元素。从那里您可以执行以下操作:
elements.css({
left: orig_left,
top: orig_top,
width: orig_width,
height: orig_height
});
样式更改将立即应用于所有元素。
但是,如果您希望将某个元素恢复为其默认值(即原始 html 中的内容),您可以执行以下操作:
elements.css({
left: null,
top: null,
width: null,
height: null
});
甚至:
elements.attr("style","");
关于jquery - 我如何知道哪个元素有一个类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10469888/