Get the App
SLTechnology News&Howtos  ›  Development  › 

How to change the width of a picture by javascript

Shulou Source: shulou.com Published: 2022-06-03 07:36:07 09月17日 Update

Javascript how to change the width of the picture, in view of this question, this article introduces in detail the corresponding analysis and answers, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Methods: 1, use the "document.getElementById ('id value')" statement to get the picture object; 2, use the "picture object .setAttribute (" width "," width value ") or" picture object .style.width = "value" statement to change the width of the picture.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

The method of changing the width of picture by javascript

1. Get the picture object according to the id value

Var img=document.getElementById ('img')

2. Use setAttribute ("width", "value") or the width property of the style object to change the width of the picture.

Img.setAttribute ("width", "width value"); / / or img.style.width = "width value"

Complete implementation code:

Tags: Pictures widths objects methods questions more sentences help answers easy easy code content guys partners properties tutorials environment computer knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux NVidia Microsoft macOS MySQL