Add padding to a HTML element in JavaScript
Description
The following code shows how to add padding to a HTML element.
Example
<!-- w w w .j a v a2 s .co m-->
<!DOCTYPE HTML>
<html>
<body>
<p id="myText">
<span id="mySpan">HTML</span>
This is a test.
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>
The code above generates the following result.
Javascript Tutorial Layout
Change left in JavaScript
Change padding bottom in JavaScript
Change padding left in JavaScript
Change padding right in JavaScript
Change padding top in JavaScript
Change position in JavaScript
Change right in JavaScript
Change top in JavaScript
Change width in JavaScript
Set div position in page scroll action in J...
Add padding to a HTML element in JavaScript
Change height in JavaScriptChange left in JavaScript
Change padding bottom in JavaScript
Change padding left in JavaScript
Change padding right in JavaScript
Change padding top in JavaScript
Change position in JavaScript
Change right in JavaScript
Change top in JavaScript
Change width in JavaScript
Set div position in page scroll action in J...