Search code examples
javascriptinnertext

Why am I losing my last empty character with .innerText?


I need to get the content a cell in a one-column table. When I use .innerText I lose the last empty character. Here is my code :

When I want to display my object (raw) :

console.log(myRow);

I get (with last character of cell empty) :

<tr class="t-state-selected">
    <td>Some data </td>
</tr>

But when I want the innetText :

console.log("'" + myRow.innerText + "'");

I get :

'Some data'

Why am I losing this last empty space ? How can I get all the data?


Solution

  • Try using .textContent instead of .innerText which trims it.

    Or if you need <IE9 support you could perhaps use .innerHTML