HTML | DOM Div align Property
Last Updated :
27 Oct, 2022
The HTML | DOM Div align Property is used to set or return the value of the align attribute of a <div> element.
Note: This property is not supported by HTML5
Syntax:
- It returns the div align property.
div object.align;
- It sets the div align property.
div object.align="left | right | center | justify "
Property Values:
- left: It sets the left-align to horizontal line.
- center: It sets the center-align to horizontal line. It is the default value.
- right: It sets the right-align to horizontal line.
- justify : It sets the content to the justify position.
Return Values: It returns a string value which represents the alignment of the Div element.
Example 1: This example returns the Div align property.
HTML
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM Div align Property
</ title >
</ head >
< body style = "text-align:center;" >
< h1 style = "color:green;" >
GeeksForGeeks
</ h1 >
< div id = "div_obj" >DOM Div align Property</ div >
< br >
< button onclick = "Geeks()" >
Click Here!
</ button >
< br >< br >
< div id = "GFG" align = "left" >
A portal for geeks.
</ div >
< p id = "geeks" ></ p >
< script >
function Geeks() {
var dv = document.getElementById("GFG").align;
document.getElementById("geeks").innerHTML = dv;
}
</ script >
</ body >
</ html >
|
Output:
Before Clicking On Button:
After Clicking On Button:
Example 2: This example sets the Div align property.
HTML
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM Div align Property
</ title >
</ head >
< body style = "text-align:center;" >
< h1 style = "color:green;" >
GeeksForGeeks
</ h1 >
< div id = "div_obj" >DOM Div align Property</ div >
< br >
< button onclick = "Geeks()" >
Click Here!
</ button >
< br >< br >
< div id = "GFG" align = "left" >
A portal for geeks.
</ div >
< p id = "geeks" ></ p >
< script >
function Geeks() {
var dv = document.getElementById("GFG").align = "right";
document.getElementById("geeks").innerHTML = dv;
}
</ script >
</ body >
</ html >
|
Output:
Before Clicking On Button:
After Clicking On Button:
Supported Browsers: The browsers supported by DOM Div align Property are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Apple Safari
- Opera
Share your thoughts in the comments
Please Login to comment...