Trending September 2023 # Guide To Examples Of Jquery Ui Trim() Method # Suggested October 2023 # Top 13 Popular | Dacvumuahe.com

Trending September 2023 # Guide To Examples Of Jquery Ui Trim() Method # Suggested October 2023 # Top 13 Popular

You are reading the article Guide To Examples Of Jquery Ui Trim() Method updated in September 2023 on the website Dacvumuahe.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 Guide To Examples Of Jquery Ui Trim() Method

Definition of jQuery trim

The jQuery UI trim() method is used to remove the whitespace from both ends of a string. The jQuery UI trim() method is a built-in method.  Sometimes we need to trim a string that removes the whitespace from the start and end of the string, but the whitespaces in the middle of the string are preserved, so jQuery provides the trim() method for this purpose. The trim() method is a string method, so when we call this method we will pass a string parameter.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

The syntax of the JQuery trim() method.

jQuery.trim( mystr ) ;

mystr – This is not an optional parameter, that specifies a string that is to be trimmed.

Return value – The return value of this method is a string after removing the whitespaces from both end.

Examples of jQuery trim

Example of jQuery UI trim() method for passing a string as a parameter.

Next, we write the HTML code to understand the jQuery UI trim() method more clearly with the following example, where the trim() method is used to remove the spaces from both sides of the string, as below.

Example #1

Code:

pre { display : block; border : 2px solid green; color : red; padding : 6px; margin : 12px; } $(document).ready(function(){ var str= “  Hello, how are you  “; $(“.original”).html(str); }); var str= ” Hello, how are you “; var trimstr = jQuery.trim( str ); $(“.trimmed”).html(trimstr); }); });

An output of the above code is:

As in the above program the string ” Hello, how are you ” is store in the str variable, if we see this string contain the whitespaces in the front and end of the string. So to remove these spaces the trim() method is used which is accepted the ” Hello, how are you ” string and returned the output as “Hello, how are you”, which is printing as we can see in the output.

Example of jQuery UI trim() method for call on string.

Next we write the html code to understand the jQuery UI trim() method more clearly with the following example, where the trim() method is used to remove the spaces from the left side of the string by calling the trim() method on the string only, as below –

Example #2

pre { display : block; border : 2px solid green; color : red; padding : 6px; margin : 12px; } $(document).ready(function(){ var str= “  Hello, how are you”; $(“.original”).html(str); }); var str = ” Hello, how are you”; str = str.trim( str ); $(“.trimmed”).html(str); }); });

An output of the above code is:

As in the above program the string ” Hello, how are you” is store in the str variable, if we see this string contain the whitespace or spaces only in the front of the string. To remove this space the trim() method is used which is accepted the ” Hello, how are you” string and returned the output as “Hello, how are you”, so the trim() method is not removed anything from the end of the string because it does not contain any space at the end as we can see in the output.

Example of jQuery UI trim() method to remove tab spaces from the front end of the string –

Next, we write the HTML code to understand the jQuery UI trim() method, where the trim() method is used to remove the tab spaces from the left side of the string.

Example #3

pre { display : block; border : 2px solid green; color : red; padding : 6px; margin : 12px; } $(document).ready(function(){ var str= “                         Hello, how are you”; $(“.original”).html(str); }); var str= “                         Hello, how are you”; var trimstr = jQuery.trim( str ); $(“.trimmed”).html(trimstr); }); });

An output of the above code is:

As in the above program the string ” Hello, how are you” is store in the str variable, if we see this string contain the tab spaces only in the front of the string. To remove this space the trim() method is used which is accepted the ”                                   Hello, how are you” string and returned the output as “Hello, how are you”.

Conclusion

The jQuery UI trim() method is a built-in method that is used to remove the spaces from both end of the string but not from the middle.

Recommended Articles

This is a guide to jQuery trim. Here we also discuss the description and Example of jQuery UI trim() method along with its code implementation. You may also have a look at the following articles to learn more –

You're reading Guide To Examples Of Jquery Ui Trim() Method

Update the detailed information about Guide To Examples Of Jquery Ui Trim() Method on the Dacvumuahe.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!