How to trigger a click on a link using jQuery

0 votes

I have a link:

<ul id="titleee" class="gallery">
  <li>
    <a href="#inline" rel="prettyPhoto">Talent</a>
  </li>
</ul>

and I am trying to trigger it by using:

$(document).ready(function() {
  $('#titleee').find('a').trigger('click');
});

But it doesn't work.

I've also tried: $('#titleee a').trigger('click');

Edit:

I actually need to trigger whatever get's called here <a href="#inline" rel="prettyPhoto">

Jun 10, 2022 in JQuery by gaurav
• 23,260 points
541 views

1 answer to this question.

0 votes

$( "#foo" ). trigger( "click" ); As of jQuery 1.3, . trigger() ed events bubble up the DOM tree; an event handler can stop the bubbling by returning false from the handler or calling 

To trigger handlers bound via jQuery without also triggering the native event, use .triggerHandler() instead.

When we define a custom event type using the .on() method, the second argument to .trigger() can become useful. For example, suppose we have bound a handler for the custom event to our element instead of the built-in click event as we did above:

1

2

3

4
$( "#foo" ).on( "custom", function( event, param1, param2 ) {

alert( param1 + "\n" + param2 );

});

$( "#foo").trigger( "custom", [ "Custom", "Event" ] );
answered Jun 10, 2022 by rajatha
• 7,640 points

Related Questions In JQuery

0 votes
1 answer

How to scroll to element from bottom to top with a nice animation using Jquery?

Hello @kartik, Assuming you have a button with ...READ MORE

answered Sep 10, 2020 in JQuery by Niroj
• 82,880 points
3,819 views
0 votes
0 answers

How to replace innerHTML of a div using jQuery?

How could I achieve the following: document.all.regTitle.innerHTML = ...READ MORE

May 31, 2022 in JQuery by Edureka
• 13,670 points
1,488 views
0 votes
1 answer

How to make a simple modal pop up form using jquery and html?

Create A Modal <button onclick="document.getElementById('id01').style.display='block'" class="w3-button">Open Modal</button> ... <div ...READ MORE

answered Jun 2, 2022 in JQuery by Edureka
• 13,670 points
6,850 views
0 votes
1 answer

How to implement a dynamic bootstrap 4 accordion, using Jquery

With this you can add dynamic accordion ...READ MORE

answered Jun 7, 2022 in JQuery by Edureka
• 13,670 points
3,426 views
0 votes
1 answer

How to trigger a click on a link using jQuery

If you are trying to trigger an ...READ MORE

answered Jun 3, 2022 in JQuery by Edureka
• 13,670 points
14,088 views
0 votes
1 answer

jQuery mouse click counter

You can use jQuery's toggleClass function for that: $(" ... ...READ MORE

answered Jun 16, 2022 in JQuery by rajatha
• 7,640 points
1,048 views
0 votes
0 answers

jQuery mouse click counter

I need to color a table in ...READ MORE

Aug 2, 2022 in Web Development by gaurav
• 23,260 points
437 views
0 votes
1 answer

TRIGGERS used in MySQL tables

The following TRIGGERS are allowed in MySQL:  BEFORE ...READ MORE

answered Aug 21, 2018 in Database by CodingByHeart77
• 3,740 points
488 views
0 votes
1 answer

How to trigger a click on a link using jQuery

Use the jQuery click() Method You can use ...READ MORE

answered Jun 10, 2022 in JQuery by rajatha
• 7,640 points
1,202 views
0 votes
1 answer

How to focus on a form input text field on page load using jQuery?

In this example the form input text ...READ MORE

answered Jun 21, 2022 in JQuery by rajatha
• 7,640 points
1,841 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP