When we think about the jquery then first thing comes in mind that is events so today we are going to discuss the custom events. Do you know about custom events? Its name has cleared the concept, means your own events. There are so many benefits of custom events. You can call the custom event using trigger function when require. It separates the code and make the code easily readable. Let's take an simple example.
jQuery(function($){
jQuery(document).on('userFeedback'{
subject:'title goes here',
function(e,param){
$('.subject').html(e.data.subject);
$('.mess').html(param);
}
});
jQuery(document).trigger('userFeedback',["user message only"]);
});
<div class="subject"></div>
<div class="mess"></div>
In above example we are simply showing user feedback and we can trigger the event any time according the our requirement. It is easy to use and easy to understand the code flow.
0 Comment(s)