tags:

views:

67

answers:

2

Hi All,

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

A: 
  • 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
Rob
+1  A: 

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.

Mark Renouf
More accurately, I'd suggest document.getElementById('Area_T10').getElementsByTagName('script')[0].src;
Paolo Bergantino