Domenico
Domenico

Reputation: 61

Issue in JavaScript retrieve information

Premise: I've started to study javascript and the DOM and I have this HTML fragment:

<body>
    <div id="Area_T10" class="abAdArea">
        <script src="http://ad.dc2.adtech.de/addyn/3.0/831/***1644116***/0/744/ADTECH;" language="javascript1.1" type="text/javascript"></script>
        <script>
            ** -- My script  var n = **
        </script>
    </div>
</body>

I want to retrieve the number "16644116" from the div but I cannot figure out how to do it.

Can you help?

Best Regards.

Domenico

Upvotes: 1

Views: 114

Answers (2)

Mark Renouf
Mark Renouf

Reputation: 30990

I am assuming you want to extract the number from the script source URL.

First step, get the script source value:

var src = document.getElementsByTagName('script')[0].src;

Then, if you're familiar with regular expressions, you should be able to create a pattern to extract that value.

Upvotes: 1

Rob
Rob

Reputation: 48369

  • Extract the URL from the attribute using whichever DOM manipulation technique you prefer (perhaps a library)
  • Use a regular expression to extract the desired portion of the URL

Upvotes: 0

Related Questions