I got this input type="text" and this button which shows the users input, but if the input have extra spaces, them will be showed too.How to remove these extra spaces form the input value?
var nameInput = $('#name');
function showName() {
if (nameInput.val() === "") {
alert('You must provide a Name');
}
else {
alert('¡Hello' + ' ' + nameInput.val() + '!')
}
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="name" />
<button type="button" onclick="showName()"> Show Name </button>