I have a piece of code that will sometimes need to be triggered by a script, but I don’t want it to change the URL on my page. (it messes up the history state for some odd reason)
The code I need to trigger:
$(".photos-bottom .albums #albums li").live("click", function() {
// my action here
});
The code I use to trigger it:
$(".photos-bottom .albums #albums li:first").trigger("click");
The link to click, however I just noticed, it’s suppose to click the li and the li is inside of the href so i don’t know why it’s still clicking it..
<a href="#/photos/1/album/42/" rel="address:/photos/1/album/42/">
<li id="42">
try
triggerHandler()instead: http://api.jquery.com/triggerHandler/Otherwise use
trigger()with anextraparameterin the call (see http://api.jquery.com/trigger/) and in your handler just check the arguments passed. If a parameter was passed then you will prevent the default link action with.<evt>.preventDefault()(note: I assume you handler is attached to links element, not to the list item, since you cannot wrap a list item into a link)