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

  • SEARCH
  • Home
  • 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 7852417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:24:48+00:00 2026-06-02T19:24:48+00:00

My HTML <div> <span class=more-available data-completeMessage=This is the complete message you see after clicking

  • 0

My HTML

<div>    
    <span  class="more-available" data-completeMessage="This is the complete message you see after clicking more">Hello</span>​
</div>

I add a anchor tag to the end dynamically and then want to attach a click handler to the anchor tag. So I do this

$(document).ready(function() {

   //Attach future proof click event to an anchor tag
   $('a.more').on('click', function() {
      var $parent = $(this).parent();
      $parent.text($parent.data('completemessage'));
   });

   //Add the anchor tag
   $('span.more-available').append($('<a class="more">...more</a>'));
});;​

This does not work. If i replace “on” by “live” it works. (but live is depreciated)

I know I can do this

$(document).ready(function() {

    $('div').on('click','a.more', function() {
        var $parent = $(this).parent();
        $parent.text($parent.data('completemessage'));
    });

    $('span.more-available').append($('<a class="more">...more</a>'));
});;​

and it works, but my question is…

Was I wrong in assuming that “on” provides all the functionality of live? Does “on” not bind to future elements? Is this correct behavior, or am I doing something wrong.

fiddle: http://jsfiddle.net/arishlabroo/pRBke/5/

  • 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-02T19:24:49+00:00Added an answer on June 2, 2026 at 7:24 pm

    on() is just a binder that allows for target delegation. It’s more of a replacement for delegate() than for live().

    $('foo').live('click',fn); is essentially $(document).on('click','foo',fn);

    With that in mind, you simply bind the click event to the constant parent wrapper and delegate to your target, like so:

    $('span.more-available').on('click', 'a.more', function(){
        var $parent = $(this).parent();
        $parent.text($parent.data('completemessage'));
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the HTML: <div id=testBlue> <span>hello</span> <span id=testGreen class=testGreen>hello2</span> </div> If I have
I have this simple html: <div class=wrapper> <span class=higher> [higher] <span class=lower> hello </span>
I've got some html that looks like this: <div> <span class=red>red text</span> some more
Suppose a HTML like this: <div id=header> <span class=title>Title</span> <!-- more spans and other
I have this HTML code which simulates a dropdown multi-checkbox <div> <div class=select> <span>Select
this is my HTML: <?php echo form_open(base_url().'admin'); ?> <div class=row username> <span class=icon></span> <input
I have a HTML like this: <div class=container> <span class=iconset></span> <!-- want to select
Html looks like: <div class=ticker> <div class=news-heading>Latest News:</div> <span class=active_ticker><a href=#> 1] Lorem ipsum
The relevant snippet of HTML: <span class=a> <div class=fieldname>Question 1</div> <input type=text value= name=q1
I have some html snippet <div id=title>This is title<span id=close>X<span><div> The width of this

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.