Add padding to a HTML element from Javascript

Description

How to change padding for a HTML element from Javascript

Example


<!DOCTYPE HTML> 
<html> 
    <body> 
        <p id="myText"> 
            <span id="mySpan">HTML</span> 
            This is a test.<!--from w w w .j a  va2 s.c o  m-->
            This is a test.
        </p> 
        <p id="myPara"> 
            This is a test.
            This is a test.
            This is a test.
        </p> 
        <script> 
            var elems = document.getElementsByTagName("p"); 
            for (var i = 0; i < elems.length; i++) { 
              elems[i].style.border = "medium double black"; 
              elems[i].style.padding = "4px"; 
            } 
            
        </script> 
    </body> 
</html>

Click to view the demo





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window