0

I am a complete newbie with javascript and jquery. I've been trying to make this code work..

var links = [];
var innerlinks = [];
var count = document.getElementsByClassName("boss").length;

for (i = 0; i < count; i++) { 
links[i] = 'http://something.com/'+ document.getElementsByClassName("boss")[i].firstChild.getAttribute("href");
};


for (j = 0; j < count; j++) {

  $.get(links[j], function(data){
    content=data;
  });

    var x = content.indexOf("<h5>Text");
    var y = content.indexOf("someothertext", x);
    var sliced=content.slice(x, y + 14);
    var z = sliced.indexOf("href=");
    var q = sliced.indexOf("style");
    innerlinks[j]=sliced.slice(z + 6, q - 2);
  };

alert(innerlinks);

..but it just doesn't seem to listen to me. I tried bunch of methods I read about here on stackoverflow but none seem to work. It's probably just some basic problem I have no knowledge about yet.

What I want this script to do is basically take the link, receive it's content, take a portion of it (a link) and store it into an array. Then move to another one.

While this one just takes a random link from the links array and fills the innerlinks array with same value. I do suspect content variable here, but I can't come up with any solution. Any and all help would be really appreciated!

  • Problem is asynchronicity. The QA I linked to should make the problem clear. – Denys Séguret Nov 03 '14 at 13:01
  • I was vary of such a problem existing, just simply too much to comprehend for a newbie all at once. I am still however struggling with applying what I read on the QA you sent me. – DontTuckIt Nov 03 '14 at 19:19
  • It's confusing at first but dealing with asynchronicity one of the most essential things to learn. You should try to understand all the answers – Denys Séguret Nov 03 '14 at 19:39
  • That's what I am going to do! Thanks for giving me the right directions, I am getting somewhere bit by bit! – DontTuckIt Nov 03 '14 at 19:52

0 Answers0