-1

I have CSS element selector, I want to remove it's CSS with the help of jQuery. How can I remove it CSS not the element input[type="button"]

Issue is CSS file where it is written I cannot change as it is coming from 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;
}
6
  • 3
    You want to remove this css-style? Commented Nov 1, 2017 at 10:17
  • Remove form the DOM/remove its styles/hide it? Commented Nov 1, 2017 at 10:17
  • Change the CSS to a class, then use removeClass() or classList.remove() in your JS Commented Nov 1, 2017 at 10:18
  • 1
    You have to use css specificity at this context. Create a new class with default styling properties and add it to the relevant elements during the runtime. You cannot remove a selector from a rendered CSS. Commented Nov 1, 2017 at 10:18
  • One suggestion can be to replace all the input[type = "button"] with div and style that div like a button Commented Nov 1, 2017 at 10:20

4 Answers 4

1

Am afraid of using this all: initial which used to set all css properties to 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()

$(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>

Sign up to request clarification or add additional context in comments.

3 Comments

This removes all button. I need to remove css
check the updated answer. am not sure about this will help or not!
No it did not works. It remove all other css class to :(
0

Just add a class to that styling and use removeClass() method... Check snippet below..

$('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"/>

3 Comments

What I understand from the question, OP wants to remove the CSS associated with input[type="button"], not the element itself
@Abhi just read question description, what OP wants I have CSS element selector which I want to remove with the help of jQuery. How can I remove it input[type="button"]
This removes all button. I need to remove css
0

There can be two ways to achieve this:

  1. With pure CSS, just override the CSS associated with
    input[type="button"] with the help of a class and !important
  2. Replace all the input[type="button"] elements with a div and have the dive styled like a button and work like a button

For example:

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

.button {
  /* CSS to stylize the div to look like a button */
}

2 Comments

Issue is CSS file where it is written I cannot change as it is coming from asp.net dll
Then can you try the second way I suggested
0

best way is use of class like this:

<input type="button" class="myButton">

And insert css codes to .myButton class like this:

.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 :

$('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!"> 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.