Loading ...

Using trim in jquery | CodeAsp.Net

Using trim in jquery

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">



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




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

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

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



<script type="text/javascript">



var txtText = $('#txtText');

var txtButtonWithoutTrim = $('#txtButtonWithoutTrim');

var txtButtonWithTrim = $('#txtButtonWithTrim');



var val = txtText.val();

var length = val.length;

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




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

var length = val.length;

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








Happy Reading.!


Comments (no comments yet)

Top Posts