Clicking an element trigger to another element in jQuery

This tutorial is going to be interesting. In this tutorial, we will click an element, but actually, the click will trigger to another element. So in this tutorial, we will learn how we can trigger clicking on an element to another element with simple and proper code snippet example using jQuery.

Let’s first write our HTML code:

<button id="clickWay">Clicking me will send you to Google</button>
<button id="googleLink" onclick="click_on_link();">Trigger click here</button>

In the above HTML code, we have created two buttons. Now we are going to do a thing when someone clicks the first button, the click will trigger the second button.

Let’s see our jQuery code:

$(document).on('click', '#clickWay', function() {

function click_on_link()
	alert("Clicked on second button done");

In the above jQuery JavaScript code, we set the click event listener on the first button and using the jQuery click method, we trigger the click event to the second button.

To check if the click triggered to the second button successfully, we have also set the click event listener to this button and set an alert message.

Upload File With Ajax Using PHP and jQuery

Disable right click, copy, cut on web page using jQuery

Now if we run our code on our browser, we will see that clicking the first button will show us the alert message that we set in the click event listener of the second button.

By getting the alert message we now confirm that clicking the first button trigger the click of another button. That means we have successfully triggered clicking an element to another element. As we are showing the alert message by clicking the second button and clicking the first button showing the alert message, then sure, clicking an element triggering the click to another element.

Easy to use PHP function to show a random image from a particular directory

2 responses to “Clicking an element trigger to another element in jQuery”

  1. Pfrimo says:

    Hey you saved my life Thanks a lot for sharing!

  2. hunter says:

    Thank you:) Great article. ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

Leave a Reply

Your email address will not be published.