Kokizzu
Kokizzu

Reputation: 26838

Getting a tag line number in browser

Is there a way to get line number of a certain tag using JavaScript?

For example, if I have the following HTML file:

<!doctype html>
<html>
  <head>
    <title>test</title>
  </head>
  <body>
    <script>
      x = "<script>"
    </script>
    <script>
    </script>
  </body>
</html>

then:

Perhaps something like document.getElementsByTagName('script')[0].lineNumber?

Upvotes: 2

Views: 241

Answers (1)

Quentin
Quentin

Reputation: 943537

Once the HTML has been through a DOM parser, any link to the source code is discarded.

You would have to refetch the HTML and then parse it yourself, keeping track of the line numbers as you go.

Upvotes: 2

Related Questions