Suppose I have an anchor in my page like :turn to header
then I also set a button in my page
Try This, working for Me !!
$("#anchor").get(0).click();
This will call default click of the anchor.
jQuery does not have a way to trigger the native DOM event directly.
To do that, you can use the plain old standard DOM methods:
var evt = document.createEvent("Event");
evt.initEvent("click", true, true);
$('#anchor').get(0).dispatchEvent(evt);
For support of IE8 or earlier, you need to use the IE-specific event methods createEventObject
and fireEvent
.
You can Also use to trigger click/any events
$('#bycategory').click(function(){
alert('triggered');
});
$('#bycategory').triggerHandler("click");
You have a spelling error. Please use:
{$("#anchor").trigger("click");});
Please see this answer.
Instead of trying to trigger the click
event, try setting the window.location
property:
window.location = '#header';
Or perhaps:
$("input").click(function() {
window.location = $('#anchor').attr('href');
});