How to set the bottom margin of an element with JavaScript?

JavascriptWeb DevelopmentFront End Scripts

Use the marginBottom property in JavaScript, to set the bottom margin.

Example

You can try to run the following code to set the bottom margin of an element with JavaScript −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <p id="myID">This is demo text.</p>
      <button type="button" onclick="display()">Set bottom margin</button>
      <script>
         function display() {
            document.getElementById("myID").style.marginBottom = "95px";
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 18:06:10
Advertisements