The HTML DOM Pre width Property is used to set or return the value of the width attribute of the <pre> element.
Syntax:
- It returns a pre width Property.
preObject.width
- It is used to set the pre width property.
preObject.width = "pixels/%";
Property Values:
- pixels: It sets the width of a predetermined text in terms of pixels.
- %: It sets the width of predetermined text in terms of percentage (%).
Return Values: It returns a numeric value that represents the width of the <pre> element.
Example 1: This example returns the width property of a pre element.
HTML
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM Input Text minLength Property
</ title >
</ head >
< body style = "text-align:center;" >
< h1 >GeeksForGeeks</ h1 >
< h2 >DOM Input Text minLength Property</ h2 >
< form id = "myGeeks" >
< input type = "text" id = "text_id"
minlength = "6" name = "geeks"
pattern = "[A-Za-z]{3}" >
</ form >
< br >
< button onclick = "myGeeks()" >
Click Here!
</ button >
< p id = "GFG" style = "font-size:20px;" ></ p >
< script >
function myGeeks() {
let txt = document.getElementById(
"text_id").minLength;
document.getElementById(
"GFG").innerHTML = txt;
}
</ script >
</ body >
</ html >
|
Output:
Example 2: Below code is to set the pre width property.
HTML
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM Input Text minLength Property
</ title >
</ head >
< body style = "text-align:center;" >
< h1 >GeeksForGeeks</ h1 >
< h2 >DOM Input Text minLength Property</ h2 >
< form id = "myGeeks" >
< input type = "text" id = "text_id"
minlength = "6" name = "geeks"
pattern = "[A-Za-z]{3}" >
</ form >
< br >
< button onclick = "myGeeks()" >
Click Here!
</ button >
< p id = "GFG" style = "font-size:20px;" ></ p >
< script >
function myGeeks() {
let txt = document.getElementById(
"text_id").minLength - "23";
document.getElementById(
"GFG").innerHTML = txt;
}
</ script >
</ body >
</ html >
|
Output: