Image widthPropiedad
Objeto Image
Definición y uso
El atributo width puede establecer o devolver el valor del atributo width de la imagen.
El atributo width especifica el ancho de la imagen.
Sintaxis
imageObject.width=pixels
Soporte del navegador
![]()
![]()
![]()
![]()
![]()
Todos los navegadores principales soportan el atributo width.
Ejemplo
Ejemplo
Cambiar la altura y el ancho de la imagen:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.com)</title>
<script>
function changeSize(){
document.getElementById("compman").height="250";
document.getElementById("compman").width="300";
}
</script>
</head>
<body>
<img id="compman" src="compman.gif.html" width="107" height="98">
<br><br>
<input type="button" onclick="changeSize()" value="Modificar el tamaño de la imagen">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Tutorial de novatos (example.com)</title>
<script>
function changeSize(){
document.getElementById("compman").height="250";
document.getElementById("compman").width="300";
}
</script>
</head>
<body>
<img id="compman" src="compman.gif.html" width="107" height="98">
<br><br>
<input type="button" onclick="changeSize()" value="Modificar el tamaño de la imagen">
</body>
</html>
Pruébalo »
Objeto Image Otras extensiones