-2

I'm trying to write a script where I programmatically click a tab, which reveals more divs on the website, and then perform some actions on those revealed divs.

Right now, I have

document.getElementById("buttonid").click(); // which reveals another section of the webpage console.log($("#idofnewdiv"));

...but it doesn't seem to see the new div. However, when I manually click on the button, console.log is able to properly print it out. Am I doing something wrong?

nauticalnits
  • 19
  • 1
  • 5

3 Answers3

0
var button = document.getElementById("buttonid");

button.addEventListener("click", function(){
   alert("Button is Clicked");
});

button.click();
Michael Paccione
  • 2,467
  • 6
  • 39
  • 74
0

too you can use it like this:

var mButton = document.getElementById("buttonId");

mButton.onClick(function(){

   your code to execute here.

});
Daniel
  • 11
  • 6
0

It doesn't look like your click function is doing anything. The following code assumes that all of the <div>s are already hidden.

var listOfDivsToReveal = document.getElementsByClassName("divsToReveal");
var listOfDivsIter = 0;
$("#thebuttonID").click(function(){
    if(listOfDivsIter > listOfDivsToReveal.length){
        //do whatever you do when all of your <div> tags are revealed
    }
    listOfDivsToReveal[listOfDivsIter++].style.display = "inline";//Or your desired display.
});
MasterBob
  • 550
  • 1
  • 8
  • 19