Say there's a button I want to click on, or a link, and there's ten of them per page and I want to control/command click them all so they load in new tabs. I do this every time, so I want to automate it. Is there a way for jQuery to target these specifically (I know how to do this), and then have them open them all in a new tab? Or is that out of jQuery's abilities?
I was thinking of making a variable for all the elements, then looping through the length of this array variable, and "control/command" clicking all of them. Is this possible?
You should be able to simulate user clicks on the links once you get the jQuery reference to them like this:
$("a.selectorClass").click();
The links themselves can specify that they open in a new window or tab, but which one is up to the user's browser preferences. I don't believe jQuery can control where those windows open.
I would think something like this might work:
$('a.class').each(function(i, obj) {
window.open(obj.href);
});
As long as they have href
attributes, anyway.
Try something like this:
$(document).ready(function() {
$("a").each(function(){
window.open($(this).attr('href'),'_blank');
});
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.