

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set the type of positioning method used for an element with JavaScript?
To set the position, use the position property in JavaScript. You can try to run the following code to set the type of positioning method used for an element with JavaScript −
Example
<!DOCTYPE html> <html> <head> <style> #box { width: 350px; height: 200px; background-color: orange; border: 3px solid red; position: relative; top: 20px; } </style> </head> <body> <p>Click to set the type of positioning method using position property.</p> <button type = "button" onclick = "display()">Set Position</button> <div id = "box"> <p>This is a div. This is a div. This is a div. This is a div. This is a div.<p> <p>This is a div. This is a div. This is a div. This is a div. This is a div.<p> <p>This is a div. This is a div. This is a div. This is a div. This is a div.<p> </div> <br> <br> <script> function display() { document.getElementById("box").style.position = "absolute"; } </script> </body> </html>
- Related Questions & Answers
- How to set an element's display type with JavaScript?
- How to set the opacity level for an element with JavaScript?
- How to set the positioning area of the background image with JavaScript?
- How to specify the type of box used for an HTML element using CSS?
- How to set the height of an element with JavaScript?
- How to set the margins of an element with JavaScript?
- How to set the padding of an element with JavaScript?
- How to set the background image for an element with JavaScript DOM?
- How to set the left margin of an element with JavaScript?
- How to set the horizontal alignment of an element with JavaScript?
- How to set the right padding of an element with JavaScript?
- How to set the maximum height of an element with JavaScript?
- How to set the bottom margin of an element with JavaScript?
- How to set the top margin of an element with JavaScript?
- How to set the right margin of an element with JavaScript?
Advertisements