Loading ...

Using trim in jquery | CodeAsp.Net

Using trim in jquery

 /5
0 (0votes)

In this blog how to use trim function in jquery. It will trim both from front and end. To explain that I have used one text box and two buttons .On click of first button an alert will be displayed with information of the value of textbox and length of the value in the textbox, and on click of second button trimmed value of textbox is displayed along with length of the value. Below is the code snippet:

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title></title>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

</head>

<body>

<div>

<input id="txtText" type="text" /><br />

<input id="txtButtonWithoutTrim" type="button" value="ValueWithoutTrim" />

<input id="txtButtonWithTrim" type="button" value="ValueWithTrim" />

</div>

</body>

<script type="text/javascript">

$(function()

{

var txtText = $('#txtText');

var txtButtonWithoutTrim = $('#txtButtonWithoutTrim');

var txtButtonWithTrim = $('#txtButtonWithTrim');

txtButtonWithoutTrim.click(function(e)

{

var val = txtText.val();

var length = val.length;

alert('Value:' + val + ' ,Length:' + length);

});

txtButtonWithTrim.click(function(e)

{

var val = $.trim(txtText.val());

var length = val.length;

alert('Value:' + val + ' ,Length:' + length);

});

});

</script>

</html>

 

 

 

Happy Reading.!

 

Comments (no comments yet)

Top Posts