Showing posts with label jquery trim string. Show all posts
Showing posts with label jquery trim string. Show all posts

jquery trim spaces - jQuery $.trim method

jquery trim spaces - jQuery $.trim method

In this tutorial, I will explain how to removes the two whitespaces at the start and at the end of the string.
Removes the two whitespaces at the start and at the end of the string.
<html>
<title>jquery trim spaces</title>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
  $(document).ready(function(){
    
    $("span").click(function () {
      var str = "     jquery trim spaces     ";
      str1 = jQuery.trim(str);
      alert(str1);
    str2 = $.trim(str);//using the jQuery $.trim method
      alert(str2);
     });
  });
  </script>
</head>
<body>
  <span>jquery trim spaces</span>
</body>
</html>


I hope this tutorial will help you to remove whitespaces at the start and at the end of the string.


Bookmark and Share

JQuery-Remove all spaces from string using javascript/JQuery/Regular expressions.

Remove all spaces from string using javascript/JQuery/Regular expressions.

In this tutorial, I will explain how to remove all spaces in a string using jquery,
remove all occurences of a character from a string.
I need to remove spaces in the string.I will use JQuery/Regular expressions/javascript to replace spaces from string.
You can replace string with '_','-'....etc.
Removing extra space from the string using javascript and Regular expression is very easy.
<script type="text/javascript">
function removeSpaces(str)
{
var s=str.replace(/\s/g, "");
return s;
}
var new_str=removeSpaces('jquery remove space from string using javascript');
</script>


Bookmark and Share