I have a menu that is usually clicked by the user. It executes a function
$('.MenuItem').click(function() {
document.writeln($(this).html() + ' was clicked');
});
I have run into a new requirement where I need to trigger the click of a menu item programmatically. So I tried
//I want to trigger click and identify the item that has been clicked. Normally, I just use
//the this object, but on a trigger I don't know how to assign this so `.html()` functions.
//This doesn't work as intended.
//$('.MenuItem').trigger('click','Item1');
How can I identify the item clicked on trigger?
You could do this in a number of ways. If you just want to use an index and click based on that:
You could also give them each an ID and click based on the ID.