function centerThis() {
document.getElementById("paragraph").style.textAlign = "center";
}
#paragraph {
text-align:left;
width:auto;
}
<p id="paragraph">
<u>
My First Paragraph
</u>
</p>
<button onclick="centerThis()">Click me</button>
As you can see, when the button is clicked, the method centerThis() is called, and the paragraph is centered. See http://www.w3schools.com/jsref/prop_style_textalign.asp for more information. I would recommend reading about DOM manipulation.
1
solved Move Paragraph With a Button