AndreaNobili
AndreaNobili

Reputation: 42957

How can I remove a specific CSS style using JavaScript?

I am absolutly new in JavaScript and I have the following problem.

I have a script that is automatically performed when the user click on a button.

I need that this script do also the following operations:

  1. Select an element into my DOM that have a specific ID

  2. This element have setted an inline CSS: style="display: block;", which have to be removed.

How can I do it?

Upvotes: 1

Views: 130

Answers (6)

EdenSource
EdenSource

Reputation: 3387

You can use .removeAttr():

$("#id").removeAttr("style");

Exemple

Upvotes: 1

heyarne
heyarne

Reputation: 1167

If you're using vanilla javascript (that is without any library), do the following:

var element = document.getElementById( YOUR_ELEMENT_ID )
element.style.display = ''

You effectively just enter the attribute you want and set it to an empty string.

Upvotes: 1

David Francis
David Francis

Reputation: 352

With JQuery you can use $("#ElementID").css("display", ""); to clear the display attribute.

If it needs to be something else, just change the second parameter in the css() function.

More info here: http://api.jquery.com/css/

Upvotes: 0

Pugazh
Pugazh

Reputation: 9561

With just JavaScript

<script>
    var elem = document.getElementById("your_elem_id");
    elem.style.display = '';    
</script>

Upvotes: 0

Adrian Bolonio
Adrian Bolonio

Reputation: 517

$("#id_of_the_element").hide();

or

$('#id_of_the_element').css('display', '');

Upvotes: 3

Jules
Jules

Reputation: 295

To remove any property, use :

  $("#id").css("the_css_property","");

Upvotes: 1

Related Questions