0

Pretty much the title. There might be a solution somewhere but I am too dumb to word it properly. So sorry if that's the case.

<head>
  <script src="javascript.js"></script>
</head>

<table>
    <tbody>
        <tr>
            <td id="test">Some random, text separated, by commas, that I will, try to separate, with filter.split(/, /);, sometime in the future </td>
        </tr>
    </tbody>
</table>
var testTd = document.getElementById('test');
console.log(testTd);

Can I make it so the console.log(testTd) output is: "Some random, text separated, by commas, that I will, try to separate, with filter.split(/, /);, sometime in the future "

Getting "ReferenceError: document is not defined" error all the time.

RUSHWAYC
  • 15
  • 4
  • I cannot reproduce. The `document` should always be defined. Sure, you [won't find the element when executing that script in the ``](https://stackoverflow.com/q/14028959/1048572), but it should still work and log `undefined`, not throw a reference error. – Bergi Jan 19 '20 at 23:36

2 Answers2

1

Put your script tag in the end of the body instead of the head

Simon Bolduc
  • 135
  • 8
-1

This should to work with jquery:

$("#test").text();

Or you can use this too:

document.getElementById ( "tdid" ).innerText
Louis B
  • 132
  • 3
  • 14
  • I don't know jQuery so other comment was more helpful since the code worked but it didn't display text, but your .innerText did. So thanks for that. – RUSHWAYC Jan 20 '20 at 13:01