Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM Input Image width Property

  • Last Updated : 16 Oct, 2019

The Input Image width Property In HTML DOM is used to return the value of the width attribute of the <input type=”image”>.

Syntax:

  • To returns the width Property.
    imageObject.width
  • To sets the width Property.
    imageObject.width = value;

Property Value: It contains the numeric value which specifies the width of the image in terms of pixels.

Return Value: It returns a numeric value which represents the width of the image.

Example 1: This Example returns the Input Image width Property.






<!DOCTYPE
<html
  
<head
    <title
        HTML DOM Input Image width Property
    </title
</head
  
<body style="text-align:center;"
  
    <h1 style="color:green;"
      GeeksforGeeks 
    </h1
  
    <h4>
      DOM Input Image width Property
    </h4
    <button onclick="my_geek()"
        <input id="myImage"
            type="image" src=
            alt="Submit" 
            formaction="#"
            formtarget="#"
            formenctype="text/plain"
            width="48"
            height="48"
    </button
    <h2 id="Geek_h" style="color:green;"></h2
    <script
        function my_geek() { 
              
            // Return formTarget, formEnctype and formAction. 
            var txt = document.getElementById( 
            "myImage").width;
            document.getElementById( 
            "Geek_h").innerHTML = txt; 
        
    </script
</body
  
</html

Output:

  • Before Clicking On Button:
  • After Clicking On Button:

Example 2: This Example sets the Input Image width Property.




<!DOCTYPE html> 
<html
  
<head
    <title
        HTML DOM Input Image width Property
    </title
</head
  
<body style="text-align:center;"
  
    <h1 style="color:green;"
      GeeksforGeeks 
    </h1
    <h4>
      DOM Input Image width Property
    </h4
    <button onclick="my_geek()"
        <input id="myImage"
            type="image" src=
            alt="Submit"
            formaction="#"
            formtarget="#"
            formenctype="text/plain"
            width="48"
            height="48"
    </button
    <h2 id="Geek_h" style="color:green;"></h2
    <script
        function my_geek() { 
              
            // Return formTarget, formEnctype and formAction. 
            var txt = document.getElementById( 
            "myImage").width = "96";
            document.getElementById( 
            "Geek_h").innerHTML = txt; 
        
    </script
</body
  
</html>                    

Output:

  • Before Clicking On Button:
  • After Clicking On Button:

Supported Browsers: The browsers supported by HTML DOM Input Image width Property are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :