In this tutorial, learn how to remove string spaces and dash using jQuery. Remove all the white spaces or dash(hyphen) from the string characters. The hyphen is the character ‘-‘ to remove from the string with jQuery.

You can also remove the spaces from the beginning or end of the string. The white space can be one or more than one in the given string. You may require to remove some or all the white spaces from the string. You may also like to read how to count string characters length using jQuery.

How to All Remove String Spaces Using jQuery

If you want to remove all the white spaces from the string, you have to use jQuery text() and replace(). The text() first get the text content from the string. The replace function replace all the white space and remove string spaces.

Output

This is my string


Click the above button to remove string spaces using jQuery. You will get a string with no spaces in its letter or character as the output.

Remove String White spaces From the Beginning and End Using jQuery

If you want to remove string spaces from the beginning or end of the string. You have to use the jQuery trim() which remove extra spaces from the start and end of the string.

Output

   This   is    my     string


The above example contains the string with some extra space at the start or end. Click the button given above to remove the start and end spaces from the string.

Remove Dash(-) Character From String Using jQuery

In addition to all the above examples, you can also remove special characters from the string. To remove the special characters like a dash(-) or hyphen, you can use the below method using replace().

Output

This-is-my-string


The above example contains the special character dash(-) among string letters. Click the above button to remove the dash(-) from the string. Check the output you get after clicking of the button. You may also like to read how to remove special characters from string using PHP.

Hope, you like this tutorial of how to remove string spaces and dash using jQuery. If you have any query regarding this tutorial, please comment below.

Also tell me, which method are you using to remove string spaces and special character from the string using jQuery.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.