How to set the horizontal alignment of an element with JavaScript?

JavascriptWeb DevelopmentFront End Scripts

To align the element horizontally, use the cssFloat property.

Example

You can try to run the following code to set the horizontal alignment of an element with JavaScript −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <img id="myID" src="https://www.tutorialspoint.com/videotutorials/images/tutor_connect_home.jpg" width="300" height="300">
      <p>This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text.
      </p>
      <button type="button" onclick="display()">Align Horizontally</button>
      <script>
         function display() {
            document.getElementById("myID").style.cssFloat = "right";
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 12:22:06
Advertisements