Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Set Margins of an Element with JavaScript



Use the margin property in JavaScript, to set the margins. You can try to run the following code to set the margins of an element with JavaScript −

Example

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <button type="button" onclick="display()">Set all four margins</button>
      <p id="myID">This is demo text.</p>
      <script>
         function display() {
            document.getElementById("myID").style.margin = "30px 20px 40px 40px";
         }
      </script>
   </body>
</html>
Updated on: 2020-06-23T13:19:12+05:30

228 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements