HTML | DOM Pre width Property
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 >DOM pre width Property</ title > </ head > < body > < center > < h1 >GeeksForGeeks</ h1 > < h2 >DOM pre width Property</ h2 > <!-- Assigning id to pre tag --> < pre id = "GFG" width = "50%" > GeeksforGeeks A Computer Science Portal For Geeks </ pre > < button onclick = "myGeeks()" > Submit </ button > < p id = "sudo" ></ p > < script > function myGeeks() { // Returning pre width property. var g = document.getElementById( "GFG").width; document.getElementById( "sudo").innerHTML = g; } </ script > </ center > </ body > </ html > |
Output:
- Before Clicking On Button:
- After Clicking On Button:
Example 2: Below code is to set the pre width property.
HTML
<!DOCTYPE html> < html > < head > < title >DOM pre width Property</ title > </ head > < body > < center > < h1 >GeeksForGeeks</ h1 > < h2 >DOM pre width Property</ h2 > <!-- Assigning id to pre tag --> < pre id = "GFG" width = "50%" > GeeksforGeeks A Computer Science Portal For Geeks </ pre > < button onclick = "myGeeks()" > Submit </ button > < p id = "sudo" ></ p > < script > function myGeeks() { // setting pre width property. var g = document.getElementById( "GFG").width = "200px"; document.getElementById( "sudo").innerHTML = g; } </ script > </ center > </ body > </ html > |
Output:
- Before Clicking On Button:
- After Clicking On Button:
Please Login to comment...