Welcome aboard! We are happy you are here and wish you good net-raft!
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunc()">Click</button></p>
Result:
<hr>
<div id="test"></div>
<script>
function myFunc() {
var str = " Hello World! ";
var a = str.trim();
document.getElementById("test").innerHTML = a;
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunc()">Click</button>
<script>
function myTrim(y) {
return y.replace(/^\s+|\s+$/gm,'');
}
function myFunc() {
var str = myTrim(" Hello World! ");
alert(str);
}
</script>
</body>
</html>
The most helpful JAVASCRIPT solutions