<div class="views" style="position: relative; width: 421px; height: 15px; overflow: hidden;">
TEST TEXT
</div>
How to remove width attribute which is under style attribute using jQuery?
I know removeAttr("width");
But it will not work here because width is child of style attribute
To remove all attributes of elements, we use removeAttributeNode() method.
The jQuery outerWidth() and outerHeight() methods get or set the outer width and the outer height of the element respectively. This outer width and height includes padding and border but excludes the margin on the element.
What defines an element's style(certainly contain width ) is the element's style attribute. In other words, the style. width ( style="width: 200px;" ) attribute determines the element's width. But some elements like canvas , svg , the width attribute will determines the element's width, if you don't set style.
You could use:
.css('width', 'auto')
As easy as
$('div.views').css('width', '');
This also worked here:
$(".views").width("");
Don't use inline styles. Use classes.
$(".views").removeClass("a");
$(".views").addClass("b");
But if you really want to, you could do the following:
$(".views").css("width", "");
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