0

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

Octtavius
  • 563
  • 8
  • 29
  • I would assume you want the remove the line breaks, not only the whitespace, have a look [here](http://stackoverflow.com/q/10805125/4202224) – empiric Sep 20 '16 at 15:11
  • I'm not sure what you mean... are you talking about the double quotes that appear above "dummyTag" ? – Shawn Sep 20 '16 at 15:16
  • @empiric No, I need it with line breaks. If I remove line breaks, I will get it as a one line string. I need it to be the same number of lines, the same structure. – Octtavius Sep 20 '16 at 15:16
  • you need to parse each line yourself and trim it accordingly – charlietfl Sep 20 '16 at 15:17
  • ![sample](http://shawnanderson.net/test/test.jpg). – Shawn Sep 20 '16 at 15:18

2 Answers2

0

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,''));
})
Netzach
  • 321
  • 2
  • 13
0

Use this just change text with html() you can get exactly the same

$('.arrangeButton').on('click', function() {
  console.log($('.copyable').html());
})
Majid
  • 2,507
  • 2
  • 19
  • 18