0

The text I need is: "BLABLA" from this code:

<td id="1" title="something">
    <span>text</span>
    <img src="pic.png"></img>
    <span><font>something</font></span>
    BLABLA
</td>

I can select the <td> element with id, but if I try to get the innerHTML value, I get the whole code inside the <td> element.

Pete
  • 57,112
  • 28
  • 117
  • 166

1 Answers1

0

You can use the lastChild property to get the last element of a container.

let MyElement = document.getElementById("1").lastChild.data.trim();
console.log(MyElement);
<table>
    <tr>
        <td id="1" title="something">
            <span>text</span>
            <img src="pic.png"></img>
            <span><font>something</font></span>
            BLABLA
        </td>
    </tr>
</table>
Cid
  • 14,968
  • 4
  • 30
  • 45