Skip to content
Related Articles
Open in App
Not now

Related Articles

How to change the text alignment using jQuery ?

Improve Article
Save Article
  • Last Updated : 07 Oct, 2021
Improve Article
Save Article

In this article, we will see how to change the text alignment of an element using jQuery. To change the text alignment of an element, we use css() method. 

The css() method is used to change the style property of the selected element.



In the below example, first, we create a <h3> element containing an id attribute and also creating a button element. When the user clicks on the button, the css() method is called and this method sets the text-align property value to the center.




<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
    <!-- Including jQuery -->
    <script src="
    <h1 style="color: green;">
        How to change the text 
        alignment using jQuery ?
    <h3 id="content">
        Welcome to GeeksforGeeks
    <button>Change font size</button>
        $(document).ready(function() {
            $('button').click(function() {
                $("#content").css("textAlign", "center");


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!