Trigger Click Events with jQuery

Trigger Click Events with jQuery
0

#1

Tell us what’s happening:
In this section, we’ll learn how to get data from APIs. APIs - or Application Programming Interfaces - are tools that computers use to communicate with one another.

We’ll also learn how to update HTML with the data we get from these APIs using a technology called Ajax.

First, let’s review what the $(document).ready() function does. This function runs such that all of the code inside of it executes only once our page has finished loading.

So Let’s start by implementing a click event handler inside of our $(document).ready() function by adding this code:

$("#getMessage").on(“click”, function(){

});
After completing this, proceed to the next challenge where we will make our “Get Message” button change the text of the element with the class message.

Your code so far

<script>
  $(document).ready(function() {
    // Only change code below this line.
    
    // Only change code above this line.
  });
</script>


<div class="container-fluid">
  <div class = "row text-center">
    <h2>Cat Photo Finder</h2>
  </div>
  <div class = "row text-center">
    <div class = "col-xs-12 well message">
      The message will go here
    </div>
  </div>
  <div class = "row text-center">
    <div class = "col-xs-12">
      <button id = "getMessage" class = "btn btn-primary">
        Get Message
      </button>
    </div>
  </div>
</div>

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36.

Link to the challenge:


#2

You did not include a question when you clicked for help. Please let us know what you need help understanding.


#3

You can simple call the click event on the button:

$("button").click();