by @kodeazy
How to remove white spaces from selected text using $(this) in JQuery?
- Using
replace
function we can replace the whitespace with empty string. -
Below is the syntax.
$(this).text().replace(/ /g,'')
-
Below is an example of how to remove
whitespace
from selected text in HTML usingthis
in JQuery.<!DOCTYPE html> <html> <body> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <p id="demo"> remove white space</p> <script> $("#demo").click(function(){ console.log($(this).text().replace(/ /g,'')); }); </script> </body> </html>