Simulate click on a div that has certain class and certain id

What I am trying to achieve (with jQuery) is this:

  $('#123').closest('.sender').trigger( "click" );

To simulate a click on a CLASS "sender" that is a class of a div with ID "123"

<div id="123" class="sender"></div> 

UPDATE: Thanks to Pranav this has been sorted. Here is the result for those who need it: https://jsfiddle.net/d35zzhcz/

Answers 1

  • The closest() method is using to get the closest ancestor element. In your case, you can combine the selectors or use filter() method instead of closest() method.

    $('#123.sender').trigger( "click" );
    // or
    $('#123').filter('.sender').trigger( "click" );
    

Related Articles