<div class="mydiv">
<ul style="height:111px; width:222px;">
...
Is it possible with jQuery (or plain javascript) to remove just the height attribute? Note that there are several instances of .mydiv ul with varying heights.
To remove inline Styles from an existing page, open your page with the editor, select the paragraph (or the entire content by pressing CTRL + A) and then click on Remove Formatting button. Inline styles, while they have a purpose, are not the best way to maintain your Web site.
To remove all CSS classes of an element, we use removeClass() method. The removeClass() method is used to remove one or more class names from the selected element.
Setting the value of a style property to an empty string — e.g. $('#mydiv'). css('color', '') — removes that property from an element if it has already been directly applied, whether in the HTML style attribute, through jQuery's . css() method, or through direct DOM manipulation of the style property.
You can remove CSS style properties from an element by setting the property to a null value, e.g. box. style. backgroundColor = null; . When an element's CSS property is set to null , the property is removed from the element.
To remove an attribute, use this:
$(".mydiv UL").css("height", "");
Thanks to am not i am for correcting my answer.
Yes! You can!
If you set the css property to a blank value, it clears it.
So, if your inline style is "background: pink" you can remove it via:
$element.css('background','')
I'm pretty sure I learned that somewhere here on SE but, alas, don't have the specific source to site, so apologies for not being able to give credit where credit is due.
UPDATE:
Well, I suppose I should have gone to the source. From the jQuery documentation (emphasis mine):
Setting the value of a style property to an empty string — e.g. $('#mydiv').css('color', '') — removes that property from an element if it has already been directly applied, whether in the HTML style attribute, through jQuery's .css() method, or through direct DOM manipulation of the style property. It does not, however, remove a style that has been applied with a CSS rule in a stylesheet or element.
http://api.jquery.com/css/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With