[英]Remove Selector CSS with Jquery
I have CSS element selector, I want to remove it's CSS with the help of jQuery.我有 CSS 元素选择器,我想在 jQuery 的帮助下删除它的 CSS。 How can I remove it CSS not the element input[type="button"]
如何删除它 CSS 而不是元素input[type="button"]
Issue is CSS file where it is written I cannot change as it is coming from asp.net dll
问题是写入的 CSS 文件我无法更改,因为它来自 asp.net dll
input[type="button"] {
min-width: 6em;
padding: 7px 10px;
border: 1px solid #ababab;
background-color: #fdfdfd;
background-color: #fdfdfd;
margin-left: 10px;
font-family: "Segoe UI","Segoe",Tahoma,Helvetica,Arial,sans-serif;
font-size: 11px;
color: #444;
}
Am afraid of using this all: initial
which used to set all css properties to initial.害怕使用
all: initial
用于将所有css属性设置为initial。
$(document).ready(function() { $("input[type='button']").css('all', 'initial'); });
input[type="button"] { background: red; color: white; border-color: red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="myContainer"> <input type="button" class="btn" value="Submit"> <input type="button" class="btn" value="Reset"> </div>
Other wise you are suppose to change all css properties using jquery css()
否则,您应该使用 jquery
css()
更改所有 css 属性
$(document).ready(function() { $("input[type='button']").css({ 'background': 'initial', 'color': 'initial' }); });
input[type="button"] { background: red; color: white; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="myContainer"> <input type="button" class="btn" value="Submit"> <input type="button" class="btn" value="Reset"> </div>
Just add a class to that styling and use removeClass()
method... Check snippet below..只需向该样式添加一个类并使用
removeClass()
方法...检查下面的代码片段...
$('input[type="button"]').removeClass('btn');
.btn { min-width: 6em; padding: 7px 10px; border: 1px solid #ababab; background-color: #fdfdfd; background-color: #fdfdfd; margin-left: 10px; font-family: "Segoe UI","Segoe",Tahoma,Helvetica,Arial,sans-serif; font-size: 11px; color: #444; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="button" class="btn" value="Button"/>
There can be two ways to achieve this:有两种方法可以实现这一点:
input[type="button"]
with the help of a class and !important
input[type="button"]
在类和!important
的帮助下input[type="button"]
elements with a div and have the dive styled like a button and work like a buttoninput[type="button"]
元素,并使潜水样式像一个按钮,像一个按钮一样工作For example:例如:
jQuery jQuery
var input_buttons = jQuery("input[type='button']");
jQuery.each(input_buttons, function(i, ele) {
jQuery(ele).replaceWith("<div class='button' onclick='...'>Submit</div>")
});
CSS CSS
.button {
/* CSS to stylize the div to look like a button */
}
best way is use of class
like this:最好的方法是使用这样的
class
:
<input type="button" class="myButton">
And insert css codes to .myButton
class like this:并将 css 代码插入到
.myButton
类中,如下所示:
.myButton {
min-width: 6em;
padding: 7px 10px;
border: 1px solid #ababab;
background-color: #fdfdfd;
background-color: #fdfdfd;
margin-left: 10px;
font-family: "Segoe UI","Segoe",Tahoma,Helvetica,Arial,sans-serif;
font-size: 11px;
color: #444;
}
so you can remove css code with this jquery code :因此您可以使用此 jquery 代码删除 css 代码:
$('input[type=button]').removeClass('myButton');
$(document).ready(function(){ $('.myButton').click(function(){ $(this).removeClass('myButton'); }) })
.myButton { min-width: 6em; padding: 7px 10px; border: 1px solid #ababab; background-color: #fdfdfd; margin-left: 10px; font-family: "Segoe UI","Segoe",Tahoma,Helvetica,Arial,sans-serif; font-size: 11px; color: #444; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <input type="button" class="myButton" value="Click Me!">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.