jQuery How to call an event function without the event being triggered

jQuery How to call an event function without the event being triggered

jquery trigger custom event
jquery trigger change event
jquery event
jquery trigger click not working
javascript trigger click event on element
jquery click
javascript trigger change event
jquery ::after click event

I have a jQuery function as shown below. I want to call the function within my javascript regardless of the whether the triggering event occurs or not. In other words, there are circumstances where I simply want to call the function below. Is it possibe?

$(document).on('change', '.jq__pAC', function(event) {
  // some working code
}); // end .on('change')

The best way to do this is as follows:

function myFunction(event)
{
   // code stuff here
}
...    
$(document).on('change', '.jq_pAc', myFunction);

This way, you can call your function at your discretion, and it will also be called by the change event.

To trigger handlers bound via jQuery without also triggering the native event, to .on() requires the information to be already computed at the time the handler is  The trigger() method triggers the specified event and the default behavior of an event (like form submission) for the selected elements. This method is similar to the triggerHandler() method, except that triggerHandler() does not trigger the default behavior of the event.


jQuery provides a way to trigger the event handlers bound to an element without any user interaction via the .trigger() method. The .trigger () function cannot be used to mimic native browser events, such as clicking on a file input box or an anchor tag. This is because, there is no event handler attached using jQuery's event system that corresponds to these events. 1. <a href="http://learn.jquery.com">Learn jQuery</a>. 1. 2.


You can separate the function from the on method, like this:

$(document).on('change', '.jq__pAC', handlerFunction);

function handlerFunction(event) {
  // some working code
}

// at some other point in your code you can call:
handlerFunction();

PS: Just for completion sake, I would recommend you extract the event variable inside the on method and pass only the appropriate info to handlerFunction. Like this:

$(document).on('change', '.jq__pAC', function(event) {
    var nodename = event.target.nodeName;
    handlerFunction(nodename);
});

function handlerFunction(nodename) {
  // some working code
}

// at some other point in your code you can call:
handlerFunction('div');

These events are often triggered by the end user's interaction with In some cases, such as the page load and unload events, the browser itself will trigger the event. event behaviors will be extended to new elements without having to with the key being the event name and the value being the function  Contains the last/previous value returned by an event handler triggered by the specified event: event.stopImmediatePropagation() Prevents other event handlers from being called: event.stopPropagation() Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event: event.target: Returns which DOM element triggered the event: event.timeStamp


So after a couple of minutes of testing and playing around with the change event I have noticed that this only works on input elements.

$(document).on('change', '.myCart-val', function(){
   if ($('.myCart-val').html() == "0") {
     $('.myCart-val').hide();
   } else {
     $('.myCart-val').show();
   }
});

What I have noticed is that for this function to actually go off I would need to apply it to some type of onclick event and the two would need to appreciate one another.

I have finally found a better solution that includes Mutation Events. Mutation events allowed my function to run accordingly when triggered by another function.

My final solution.

if ($('.myCount').text() == "0"){$('.CartCount').hide();}

$('.myCart-val').on('DOMSubtreeModified', function() {
   if ($(this).text() == "0") {
     $(this).hide();
   } else {
     $(this).show();
   }    
});

I found my answer here.. Hope it helps you

being executed, this method also stops the bubbling by implicitly calling event. therefore, may prevent the delegated handler from triggering by calling event. link jQuery Event Basics link Setting Up Event Responses on DOM Elements. jQuery makes it straightforward to set up event-driven responses on page elements. These events are often triggered by the end user's interaction with the page, such as when text is entered into a form element or the mouse pointer is moved.


triggerHandler( "event" ) method will not call .event() on the element it is triggered whatever value was returned by the last handler it caused to be executed. The event object is always passed as the first parameter to an event handler. An array of arguments can also be passed to the .trigger() call, and these parameters will be passed along to the handler as well following the event object. As of jQuery 1.6.2, single string or numeric argument can be passed without being wrapped in an array.


A handler function previously attached for the event(s), or the special value false Calling .off() with no arguments removes all handlers attached to the elements. all of the arguments provided must match for the event handler to be removed  jQuery calls a handle hook when the event has occurred and jQuery would normally call the user's event handler specified by .on() or another event binding method. If the hook exists, jQuery calls it instead of that event handler, passing it the event and any data passed from .trigger() if it was not a native event.


A function to execute each time the event is triggered. Namespacing allows us to unbind or trigger some events of a type without affecting As of jQuery 1.4.2 duplicate event handlers can be bound to an element instead of being discarded. .on() method takes an event type and an event handling function as arguments. Optionally, it can also receive event-related data as its second argument, pushing the event handling function to the third argument. Any data that is passed will be available to the event handling function in the data property of the event object. The event handling