<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="text">Javascript is -</p>
<button id="firstpara">Click Me</button>
<script type="text/javascript">
document.getElementById("firstpara").onclick = function() {
document.getElementById("text").innerHTML = "I THINK " + document.getElementById("text").innerHTML + " awesome";
}
</script>
</body>
</html>
https://jsfiddle.net/xpvt214o/411211/
The code adds "I think" before "javascript is" and "awesome" at the end when the button is clicked.
This doesn't work as expected it adds I think is awesome after The Text Javascript is
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<p id="text">Javascript is -</p>
<button id="firstpara">Click Me</button>
<p id="empty"></p>
<button id="createText">Create Text</button>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$("#firstpara").click(function() {
$("#text").append("I think ") + $("#text").html() + $("#text").append(" is awesome");
});
</script>
</body>