Octtavius Octtavius - 2 months ago 6
HTML Question

Why can't I remove whitespace of each html line?

I tried a lot ways such as .trim() or replace bot nothing worked.
https://jsbin.com/biguqe/4/edit?html,js,console,output

Here is my html. I need on click to get the content within 'code' tag exactly as it is. But I get the content with the whitespace that you see from the edge of the screen to the content.

<div class="wrapper">
<code class="copyable">
&lt;dummyTag<br>
id="page"<br>
navButtonPress="onNavBack"<br>
showNavButton="{device&gt;/system/phone}"<br>
title="{i18n&gt;detailTitle}"<br>
busy="{detailView&gt;/busy}"<br>
busyIndicatorDelay="{detailView&gt;/delay}"&gt;<br><br>
&lt;dummyTag:positiveAction&gt;
<&lt;dummyTag:PositiveAction&nbsp;id="approveButton"&nbsp;press="onApprove"&nbsp;text="{i18n&gt;xbut.approve}"/&gt;<br>
&lt;/dummyTag:positiveAction&gt;<br>
&lt;dummyTag:negativeAction&gt;<br>
&lt;dummyTag:NegativeAction&nbsp;id="rejectButton"&nbsp;press="onReject"&nbsp;text="{i18n&gt;xbut.reject}"/&gt;<br>
&lt;/dummyTag:negativeAction&gt;<br>
<br>
&lt;semantic:content&gt;<br>
</code>
<button class="arrangeButton">Arrange</button>
</div>


Here is my code: https://jsbin.com/biguqe/4/edit?html,js,console,output

Answer

I add .replace(/ /g, '') to your code, please, see if is that you want or not... because I don't understand.

$('.arrangeButton').on('click', function() {
  console.log($(this).siblings('.copyable').text().replace(/ /g,''));
})