I have 2 divs with 2 different class:
-
div class name is: good
-
div class name is: bad
I would like to click with javascript (user script) randomly for this divs. I never coded in javascript i just found this code in internet.
I have this code:
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js");
script.addEventListener('load', function() {
var script = document.createElement("script");
script.textContent = "(" + callback.toString() + ")();";
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
function main() {
setInterval(function(){
$('div.good').click();
$('div.bad').click();
}, 5000);
}
addJQuery(main);
It seems like what you are looking to do is perform an action with one of these two divs. It doesn’t really make sense to fake a click, because all that does is run code, which could just as easily be executed in another, far more convenient manner. What do you want to happen when the div is clicked?