How do I change or remove style "width" property for img?
.main_box_img img {
width: 100%;
}
<div class="main_box_img">
<img src="...">
</div>
document.getElementsByClassName("main_box_img")[0].getElementsByTagName('img')[0].style
is empty.
I can get width value using getComputedStyle()
, but it’s read-only.
Seems to be a simple question but I’ve found nothing.
4
Answers
if you need to remove a style from an element you could just use a specific modifier class for this purpose and then remove it via JavaScript.
e.g.
By removing that class the style will no longer affect the element.
to alter the style sheet you can use the following code which is just a simple example:
in this example you always know the second css rule in your stylesheet is the one that needs to be changed this way of coding is not preffered but it is the way you wanted it i believe
You can either:
Creating a css class for images within
.main_box_img
withwidth: 100%
will enable removing the class later on. Furthermore: withquerySelector[All]
you can improve selecting elements (with elaborate css query selectors)