0

I'm adding a element to a page so that multiple items on a list are clicked. I've done some jQueries to catch all the elements that I want to download, but I can't click on them with a loop. When I do a loop to click them all, only the first one is clicked.

This code makes a list, set the element target to a new window, then clicks on it. Should be a few elements on the list, so a click can be send to multiple entries.

function ClickThemAll() {
    .
    .
    .
    for (var i = 0; i < len; i++) {
        var element = list.pop();
        element.target="_blank";
        element.click();
    }
    .
    .
    .

}

The problem is that a click is sent to the first element only, and I want it to send to all elements. I tried using setTimeout(), but it just sent multiples clicks to the same element. I need help to click them all, even with a small delay from clicks is okay.

P.S.: The list in the code would be an array of the elements. Forgot to add it.

  • What is `list`? Note that [click()](https://api.jquery.com/click/) only triggers a click on the first element of a selection. Use [get()](https://api.jquery.com/get/) in a loop to get specific element of the matching selection and call click() on that. – Capricorn May 31 '18 at 19:38
  • Perhaps [this](https://stackoverflow.com/questions/906486/how-can-i-programmatically-invoke-an-onclick-event-from-a-anchor-tag-while-kee) answer might be useful? I'm pretty sure you want to be `apply()`ing onclick instead of invoking it. – DavidW May 31 '18 at 19:52
  • @DavidW I read it, and if my bad Javascript knowledge did work, the link you sent was to add a `onclick` event to a clicked element. Not the case here. I'm trying to take n elements from a list, and send a click on each of them. Still gonna read it again to make sure. – Ryuzaki dono Jun 01 '18 at 00:19
  • @Capricorn `get()` didn't work, returned an `not a function` nonsense. But using `list[i]`or `list.pop() works to get the elements, the console shows me the data. – Ryuzaki dono Jun 01 '18 at 00:22

1 Answers1

0

Ok, my mistake. The code worked all right, i just forgot to allow the pop-ups for the site.

A for with multiple clicks was ok, just allow the pop-ups.