3

I have a table and I want to make cell editable by showing the input element when user click the cell and I want to give the same height and width to input that cell have. The problem is I am using Angular Material and they have some style on input element (not through class) and it overrides the class or inline style which I am trying to apply on input element. So how can I remove those style from input element with jQuery?

Css is apply like this

input {
-webkit-appearance: textfield;
background-color: white;
-webkit-rtl-ordering: logical;
user-select: text;
cursor: auto;
padding: 1px;
border-width: 2px;
border-style: inset;
border-color: initial;
border-image: initial;
}
5
  • 4
    .removeAttr('style') Commented May 16, 2017 at 9:49
  • show what you are doing.. Commented May 16, 2017 at 10:00
  • currently I have not idea because to remove class removeClass can be used and to remove inline css .removeAttr('style') can be used but for this I don't know Commented May 16, 2017 at 10:03
  • If you don't want those styles, why can't you just override those styles with your own by using a more specific selector? Also, why do you need to use jquery to remove the style instead of just doing it with css? Show your class that is overriden Commented May 16, 2017 at 10:05
  • i suggest just override the previous with what ever style you want. by adding a class or id with style. ID will be the most ideal selector to use then put what ever style you want Commented May 16, 2017 at 10:16

4 Answers 4

5

You can do it with jQuery like below

$("input").focus(function(){ $(this).css("all","unset"); });
input {
-webkit-appearance: textfield;
background-color: white;
-webkit-rtl-ordering: logical;
user-select: text;
cursor: auto;
padding: 1px;
border-width: 2px;
border-style: inset;
border-color: red;
border-image: initial;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text"  />

You can do it with css like below

input {
-webkit-appearance: textfield;
background-color: white;
-webkit-rtl-ordering: logical;
user-select: text;
cursor: auto;
padding: 1px;
border-width: 2px;
border-style: inset;
border-color: red;
border-image: initial;
}

input:focus {
  all: initial;
  * {
    all: unset;
  }
}
<input type="text"  />

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

4 Comments

border is gone.
Welcome. you can use this if you want to do it in jquery. $("input").focus(function(){ $(this).css("all","unset"); });
Not the best solution. When you then set any CSS attribute - at least in Chrome - all other attributes are set explicitly as unset. $("input").removeAttr('style'); is the better solution.
0

You can use this:

$(document).ready(function(){
  //$("#inp1").removeAttr('style');
  $("input").removeAttr('style');
  //$("input [type='text']").removeAttr('style');
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" style="height:40px;" id="inp1"/>

Comments

-1

For inline css use removeAttr('style') but for the styles getting applied via css, you need to remove classes as well. use removeAttr('class') for this.

if the css is applied on tag, thenbest way is to add a class like active and add the css you want to it like .active { border-style: none, ... } etc.

3 Comments

but css is not apply through class it is applied like this input { -webkit-appearance: textfield; background-color: white; -webkit-rtl-ordering: logical; user-select: text; cursor: auto; padding: 1px; border-width: 2px; border-style: inset; border-color: initial; border-image: initial; }
then you need to remove the styles one by one but the best way is to add a class like active and add the css you want to it like .active { border-style: none, ... } etc.
if you find the answer useful, then please upvote it.
-1

$("class/tag/id").removeAttr('style/class/id');

2 Comments

it is not applied through class but through element like this input{}
You can use any selector . I just given an example

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.