从多个类中删除 Attr
removeAttr from multiple classes
是否可以从多个类和 ID 中使用 removeAttr? 我找不到任何东西。
像这样的 smth $('.one.two.six.eleven#box').removeAttr("style");
和这个都不起作用
$(".one.two.three#smth.seven").css("transition", "3s");
我无法设法在多个类和 id 上使用 removeAttr,这些类和 id 不是彼此:)的子级。
我也无法设法将 CSS() 添加到 Windows 中的许多免费类中,每个类都有自己的参数,但有一些绑定来处理所有这些参数。
在小提琴中,我有一些基本的工作,但对我来说太长了太多的行。 似乎很糟糕。
谢谢大家的回答。
我放置JSfiddle来显示我制造的混乱,但想做"DRY"和"LIM"。
摆弄叉子...
解释的新编辑
function some_func() {
$(".some").removeAttr("style");
$(".thing").css("transition", "3s");
$(".right").removeAttr("style");
$(".right").css("transition", "3s");
$(".left").removeAttr("style");
$(".left").css("transition", "3s");
$(".hello").removeAttr("style");
$(".top").css("transition", "3s");
$("#car").removeAttr("style");
}
如何制作 2 行
$(".one.two.three#smth.seven")
表示您正在选择一类、二类、类三类等的所有对象。 (我什至不认为三个#smth会起作用)。
例如:<div class="one two three">
将由$(".one.two.three")
选择
如果要将来自多个选择器的对象并集,可以逗号分隔它们:
$(".one, .two, .three, #smth, .seven")
这应该返回所有 .one 或 .two 或 .three 或 #smth 或 .seven 的对象
即 <div class="one"></div><div class="two"></div><div class="three"></div>
都将被选中。
试试这个,
$('button').on('click',function(){
$('.one,.three,.five').removeAttr('class');
$('#two,#four').removeAttr('id');
});
li{
color: green;
}
.one{
color:red;
}
#two{
color:blue;
}
.three{
color:purple;
}
#four{
color:yellow;
}
.five{
color:black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button>click me</button>
<ul>
<li class="one">1</li>
<li id="two">2</li>
<li class="three">3</li>
<li id="four">4</li>
<li class="five">5</li>
</ul>
如果可以为所有这些元素添加一个公共类,则可以使用该类删除属性。
例如-
目录
<div class="position right"></div>
<div class="position left"></div>
<div class="position hello"></div>
<div id="car" class="position"></div>
溶液
$('.position').removeAttr('style')
$(document).ready(function() {
$("#buttonella").click(function() {
$('.right').addClass('right-toggle');
$('.right1').addClass('right1-toggle');
$('#box').addClass('box-toggle');
});
$("#buttonella2").click(function() {
$('#box').removeClass("box-toggle");
$('.freebox').removeClass();
$(".left").css("background", "pink");
$('.right').removeClass('right-toggle');
});
})
:root {
padding: 20px;
}
[class] {
margin-left: 10px;
margin-top: 50px;
}
#buttonella {
color: blue;
font-size: 30px;
float: left;
}
#buttonella2 {
color: blue;
font-size: 30px;
float: right;
}
.box-toggle {
background: red;
width: 300px;
margin: 0px;
font-size: 20px;
display: block;
}
.right-toggle, .right1-toggle {
background: green;
width: 200px;
font-size: 30px;
display: block;
}
.freebox {
background: red;
width: 400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="buttonella">click</div>
<div id="buttonella2">unclick</div>
<div id="box">boxboxboxbxo bxoxboxbox
<div class="right">right rith ehiteh hereee
</div>
<div class="left">left left left here
</div>
<div class="right1">right1 class is here
</div>
</div>
<div class="freebox">freebox class is here
</div>
- 使用php或javascript从facebook相册URL中删除多余的部分
- RegEx删除空属性?例如,如果(class=“”||class=“”)移除;否则就下课
- 如何删除多行HTML排列中的空白
- 如何从rails中的代码中删除新行( )
- 删除对HTML元素的拖动
- 当图像转换为本地存储的DataURL时,EXIF被删除
- 按顺序添加和删除类
- iframe正在添加标签,需要删除它们
- 如何在HTML输入字段中添加不可删除的后缀
- addData()从最新图表中删除.js 2.1.3-怎么了
- 如何覆盖锚点元素's href目标,并在我点击转到目标javascript时删除其他错误
- 删除CKEditor工具栏按钮,但不删除功能
- 当浏览器上的后退按钮到达主页时,我需要删除Class
- 从多个类中删除 Attr
- Jquery attr src 从 src 中删除了一个字符串,但没有删除更复杂的字符串,为什么
- 在绑定或删除点击时 ATTR 失败
- 如何在鼠标退出时删除 attr() 值
- Jquery.attr和.prop删除Chrome中的属性
- 使用attr jquery删除样式属性
- 删除Attr不会删除禁用的内容