Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove width attribute which is under style attribute using jQuery?

Tags:

jquery

<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

like image 456
Fero Avatar asked Nov 03 '11 13:11

Fero


People also ask

What jQuery method is used to completely remove attributes from elements?

To remove all attributes of elements, we use removeAttributeNode() method.

What jQuery effect alters the width of an element?

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.

How do you change the width of a style in HTML?

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.


4 Answers

You could use:

.css('width', 'auto')
like image 191
Avaq Avatar answered Oct 07 '22 04:10

Avaq


As easy as

$('div.views').css('width', '');
like image 35
Yuri Ghensev Avatar answered Oct 07 '22 04:10

Yuri Ghensev


This also worked here:

$(".views").width("");
like image 23
warvariuc Avatar answered Oct 07 '22 04:10

warvariuc


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", "");
like image 7
jrummell Avatar answered Oct 07 '22 04:10

jrummell