Limpar campos vazios
Limpar campos vazios trim
by Rapha Souza
HTML
<script src="//code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="//stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<!DOCTYPE html>
<html>
<body>
<p id="2">Click the button </p>
<div class="form-group col-md-3">
<label for="DESDEPAR">DESDEPAR</label>
<input type="text" class="form-control" name="DESDEPAR" id="DESDEPAR">
</div>
<button onclick="myFunction()">Try it</button>
<p><strong>Note:</strong> The trim() method is not supported in Internet Explorer 8 and earlier versions.</p>
<script>
function myFunction() {
var str = " Hello World! ";
alert(str.trim());
// Descricao Departamento
var desdepartTable = document.getElementById("2").innerHTML;
// alert(emailTable);
alert(desdepartTable.trim());
var tratado = desdepartTable.trim();
document.getElementById("DESDEPAR").value = tratado;
}
</script>
</body>
</html>