jQuery assign event handler with timeouts per element

You could store the time variable using jQuery's data method which can store data on each of your elements.

$('body').on('mousemove', '.cont', function(){

  var thiis = $(this),
      // get the time from the data method
      time = thiis.data("timer-id");

   if (time){


   var new_time = setTimeout(function(){
   }, 2000);

   // save the new time
  thiis.data("timer-id", new_time);

One simple and direct approach is to do what you always do when you want to reuse functionality: Make it a function you can call from more than one place:

// The original handler
function originalHandler() {
    alert('I was clicked');

// Hooking it up, not including the special element

// Hooking up your additional handler
    alert('Extended click');
    originalHandler.call(this, e);

Live Example

When initially creating the array you could instead add a unique CSS class to each of them. This would allow you to use a jQuery selector to return all the elements and bind the additional behavior to them all at once.

If you need to add or remove elements from the array you could add or remove the class from the elements. You can cache the results of the jQuery selector for similar performance to the array you're using.

You could delegate it to modal div level:

$('#commentDelete').on('click', '#confirmDeleteComment', function () {

You can use jQuery.on method. It can attach handlers to all existing in the DOM and created in future tags of the selector. Syntax is as follows:

$(document).on('click', '.toBuyItem', function(){
//do onClick stuff

Message :
Login to Add Your Comments .
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © bighow.org All Rights Reserved .