Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
113
rated 0 times [  115] [ 2]  / answers: 1 / hits: 48289  / 14 Years ago, mon, may 24, 2010, 12:00:00

I got HTML element contains this:



  <!--Product Style-->  <div style=float: right; padding-top: 4px; padding-bottom: 5px;>  P6C245RO </div>  <div style=text-transform: uppercase; font-weight: bold; padding-top: 4px; padding-bottom: 5px;>  Style </div>  <div style=clear: both; border-top: 1px solid rgb(216, 216, 216); padding-top: 4px;>  <!--Product Description-->  <div style=font-size: 11px ! important;></div>  <div style=background: url(&quot;http://ii.armaniexchange.com/ArmaniExchange/images/en_US/global/globalgraphics/bullet.gif&quot;) no-repeat scroll 0pt 4px transparent; padding-left: 12px;>fine tonal striped fabric</div>  <div style=background: url(&quot;http://ii.armaniexchange.com/ArmaniExchange/images/en_US/global/globalgraphics/bullet.gif&quot;) no-repeat scroll 0pt 4px transparent; padding-left: 12px;>epaulettes and sleeve tab</div>  <div style=background: url(&quot;http://ii.armaniexchange.com/ArmaniExchange/images/en_US/global/globalgraphics/bullet.gif&quot;) no-repeat scroll 0pt 4px transparent; padding-left: 12px;>metal logo plate on the chest pocket</div>  


When i read it using jquery i get the .text() contains a lot of spaces and /n in between the text but without the html tags.



How to remove all these white spaces and return the clean text using jquery or pure javascript?


More From » jquery

 Answers
23
element.text().replace(/s+/g,  );


This uses a regular expression (/.../) to search for one or more (+) whitespace characters (s) throughout the element's text (g, the global modifier, which finds all matches rather than stopping after the first match) and replace each with one space ( ).


[#96697] Thursday, May 20, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
montana

Total Points: 675
Total Questions: 86
Total Answers: 102

Location: Mali
Member since Fri, Dec 3, 2021
3 Years ago
;