How to change the background image using jQuery
How to Detect a Mobile Device
offset vs position in jQuery
Checkbox validation in jQuery
Use of moment JS to change date format in jquery
jQuery Redirect to Another Page After 5 Seconds
JQuery Validation
jQuery get Difference between two Dates in days
Dynamic Drag and Drop table rows using JQuery Ajax
Add Edit Delete Table Row in JQuery
Add remove input fields dynamically using jQuery with Bootstrap
JQuery photo gallery with thumbnail
Dynamically Add Remove input fields using JQuery Ajax
Barcode jQuery example
jQuery Timepicker
Read more functionality using jQuery
jQuery CDN
JQuery Pagination
Get Selected Value in Drop-down in jQuery
JQuery Input Mask Phone Number Validation
Integrate jQuery Fullcalendar using Bootstrap, PHP and MySQL
Allow only 10 numbers in textbox using Jquery
JQuery left side menu
Automatically Refresh or Reload a Page using jQuery
Lazy load images using jQuery
Create a Tic TAC Toe Game using jQuery
How to Convert an HTML Table into Excel Spreadsheet using jQuery
Import Excel data into HTML table using JQuery
Create a To-Do list using JQuery
JQuery Page Pilling
QR Code Generator using HTML, CSS, and jQuery
Phone Number Keyboard using HTML and jQuery
JQuery UI Checkboxradio
How to Create a Custom Image Magnifier using jQuery
JQuery UI Control groups
How to create a simple map using jQuery
JQuery Blockrain/ Tetris game
How to display a digital clock using HTML, CSS, and JavaScript
JQuery Multiscroll.js
JQuery Sort
JQuery Calendar
JQuery menu-aim plugin
JQuery Typewriter
JQuery Product Tour
Upload image with progress bar using jQuery
How to add options to a select element using jQuery
How to remove close button from jQuery UI dialog using jQuery and css
JQuery Crop Plugin
Vertical Dot Navigation Plugin
jQuery jTippy Tooltip Plugin
Create a 3D Text Effect using HTML and CSS and jQuery
Jquery Flickerplate Plugin
jQuery bootstrapSelect Plugin
Froala editor plugin
Gauge chart plugin using jQuery
Horizontal Scrollable Timeline Plugin - jTimeline
Skype Chat jQuery Plugin
Whatsapp Chat Widget
Twenty Twenty jQuery Plugin to Compare Images
jQuery Filter Table
Language Translation with JavaScript
jQuery Animated Border Plugin
jQuery Palette Color Picker
jQuery Excel Export Plugin Library
jquery social counter plugin
jQuery Page Flip
How to create an online radio using jQuery and jPlayer
jQuery File manager for web
Automatically Format your Numbers and Currencies using jquery
jquery cookie consent plugin
jQuery Coverflow widget
jQuery PayPal HTML Shop
Full Screen video Background using jquery
jQuery Push Notification Plugin
Create a menu item animation on hover
Jquery Countdown Timer
Jquery dragStart Event
Jquery dragStop event
Picture Puzzle Game using Jquery
Jquery Captcha Widget
Jquery Search Slide out Plugin
Miscellaneous
jQuery vs AngularJS
jQuery MCQ
jQuery MCQ
jQuery UI
50+ jQuery UI
Interview Questions
jQuery Questions
jQuery trim() method
The
trim()
method is used to remove the space, tabs, and all line breaks from the starting and end of the specified string. This method does not remove these characters if these whitespace characters are in the middle of the string.
The commonly used syntax of using this method is given as follows.
Syntax
jQuery.trim( str )
The
trim()
method accepts single parameter
str,
which is defined as follows.
str:
It is a string that is required to be trimmed.
Example
In this example, first, we have to click the given button. After clicking the button, an alert box will be displayed showing the original string. On closing the corresponding alert box, another alert box will be displayed that shows the trimmed string.
Here, the original string contains multiple new lines, tabs, and spaces at the beginning, as well as at the end of the string.
<!DOCTYPE html>
<title> jQuery trim() method</title>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<h4> This is an example of using trim() method </h4>
<p style = "color: blue;"> Click the following button to trim the string </p>
<button id = "btn"> Click me </button>
<script>
$(document).ready(function(){
$("#btn").click(function(){
var str = "\n\n Welcome to the javaTpoint.com \n\n";
alert("The original string is: " + str);
str = jQuery.trim(str);
alert("The trimmed string is: " + str);
</script>
</body>
</html>
Test it Now
Output:
After the execution of the above code, the output will be -
After clicking the given button, the output will be -
On closing the alert dialog box, we will get the trimmed string as shown below:
Next Topic
jQuery getJSON() method