Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7992565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:35:56+00:00 2026-06-04T13:35:56+00:00

Is there the equivalent of the jQuery livequery plugin for jQuery 1.7+ ? I’m

  • 0

Is there the equivalent of the jQuery livequery plugin for jQuery 1.7+ ?

I’m trying to dynamically bind events, reading the events a DOM element should bind on based on data-* elements.

<a href="#" class="js-test" data-events="click">Test 1</a>
<a href="#" class="js-test" data-events="mouseover">Test 2</a>
 .. etc ..

I want to bind all elements with class .js-test but only on the events listed in their data-events attribute.

jQuery.on/live/bind/delegate all require the events to be passed in as params.

This is find for DOM elements that exist on the page when document.ready, however as I update the DOM (AJAX, JS, etc.) I want any new elements with class .js-test to have its events bound as well.

The livequery plugin (which is old, from jQuery 1.3 times) seems to allow this, as it simple requires a selector and a function to run against anything that matches the selector.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T13:35:58+00:00Added an answer on June 4, 2026 at 1:35 pm

    As of jQuery 1.7 the on method, supercedes the live method. While it doesn’t have an easy method of passing in or matching selectors like you describe, it is possible to accomplish this by passing in the dynamic value of data-events in place of the event type, as long as the data-event value matches that event.

    However, since the argument passed into the on method’s event parameter — the first parameter — is taken from each data-events attribute, from each element in the set of matched elements, we must loop through the collection of matched elements so that we access each elements’ individual data-events attribute value separately:

    $('.js-test').each(function() { 
        $(this).on( $(this).attr("data-events"), function() {
    
            // event pulled from data-events attribute           
            alert("hello - this event was triggered by the " + $(this).attr("data-events") + " action.");
    
        });
    });
    

    I want all events to be mapped to the same function, but have different events trigger the function call for different DOM elements.

    Since you want to map all of the events to a single function, this solution meets your specific requirements, and solves your problem.

    However, should your requirements change and you find you need to map a collection of function events to match each event type, this should get you started:

    var eventFnArray = [];
    eventFnArray["click"] = function() { 
        alert("click event fired - do xyz here");
        // do xyz
    };
    eventFnArray["mouseover"] = function() { 
        alert("mouseover fired - do abc here"); 
        // do abc
    };
    
    $('.js-test').each( (function(fn) { 
    
       return function() {   
         $(this).on( $(this).attr("data-events"), function() {
    
            alert("hello - this is the " + $(this).attr("data-events") + " event");
    
            // delegate to the correct event handler based on the event type
            fn[ $(this).attr("data-events") ]();
    
         });
       }
    })(eventFnArray)); // pass function array into closure
    

    UPDATE:

    This has been tested and does indeed work for new elements added to the div#container. The problem was in the way the on method functions. The delegating nature of on only works if the parent element is included in the selector, and only if a selector is passed into the second parameter, which filters the target elements by data-events attribute:

    HTML:

    <div id="container">
        <a href="#" class="js-test" data-events="click">Test 1</a>
        <a href="#" class="js-test" data-events="mouseover">Test 2</a>
    </div>
    

    JavaScript:

    $(document).ready(function() {
      $('.js-test').each(function() { 
          var _that = this;
          alert($(_that).attr("data-events"));
    
          $(this).parent().on(
              $(_that).attr("data-events"), 
                  '.js-test[data-events="'+ $(_that).attr("data-events") +'"]', 
                  function() {
    
                      // event pulled from data-events attribute           
                      alert("hello - this event was triggered by the " + $(_that).attr("data-events") + " action.");
                  }
              );
          }
      ); 
    });
    

    Additionally, use the following jQuery to add an item to the container to test it:

    $('#container')
        .append("<a href='#' class='js-test' data-events='mouseover'>Test 3</a>");
    

    Try it out:

    Here is a jsfiddle that demonstrates the tested and working functionality.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

jQuery lets you do things like $div.bind('click.namespace', function) $div.unbind('click.namespace') Is there any equivalent in
Is there a jQuery equivalent to do the following: $(document).ready(function() { for an element:
Starting Situation These two commands should be equivalent. jQuery('a').filter(':contains(about)'); and jQuery.find('a').filter(':contains(about)'); Problem In fact,
Is there some equivalent to jQuery's getScript in Prototype ?
Is there any equivalent for setTimeout and clearTimeout functions in jquery 1.4.2.... I found
Is there an easy way to do the equivalent in jquery or jscript for
I would like to know if there is any equivalent to the jquery mousemove
Is there an equivalent of ASP.NET's ModalPopup in jQuery UI?
Is there a CSS3 equivalent to .fadeToggle() in jQuery? I was googling around after
I'm looking for a jQuery(or jQuery plugin) equivalent of this C# code block. What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.