DOM style textAlign गुण HTML दस्तावेज़ में ब्लॉक स्तर के तत्व में टेक्स्ट के क्षैतिज संरेखण को लौटाता है और संशोधित करता है।
सिंटैक्स
निम्नलिखित वाक्य रचना है -
-
रिटर्निंग टेक्स्टएलाइन करें
object.style.textAlign
-
2. टेक्स्ट को संशोधित करना संरेखित करें
object.style.textAlign = “value”
उदाहरण
आइए स्टाइल टेक्स्ट एलाइन प्रॉपर्टी का एक उदाहरण देखें -
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
background: lightblue;
height: 100vh;
}
p {
border: 2px solid #fff;
margin: 1.5rem auto;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
}
</style>
</head>
<body>
<h1>DOM Style textAlign Property Example</h1>
<p>This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text. This is paragraph 1 with some dummy text.</p>
<button onclick="add()" class="btn">Set textAlign</button>
<script>
function add() {
document.querySelector('p').style.textAlign = "center";
}
</script>
</body>
</html> आउटपुट
यह निम्नलिखित आउटपुट देगा -

“पाठ्यसंरेखण सेट करें . पर क्लिक करें अनुच्छेद तत्व के अंदर पाठ को संरेखित करने के लिए बटन।
