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 7679389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:51:59+00:00 2026-05-31T17:51:59+00:00

i have 2 lines jquery. first line is adding event on myLink and second

  • 0

i have 2 lines jquery. first line is adding event on “myLink” and second line adding class “myLink” on “#another” but event is not working in second one but when i am using .live method then it is wokring. jquery introduce .on method in its 1.7 version. i want to do that it by .in function is this possible.

$(function(){

    $("a.myLink").on('click', function() { alert( 'Click!' ); } );

    $("a#another").addClass( "myLink" );
})



<a class="myLink">A link!</a>
<a id="another">Another link!</a>
  • 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-05-31T17:52:01+00:00Added an answer on May 31, 2026 at 5:52 pm

    I just wrote a primer on using .on() to replace .live() and explained both the static form of .on() (which you are using) and the dynamic form of .on() (which you need to be using). That primer from earlier today is here: Does jQuery.on() work for elements that are added after the event handler is created? which contains a lot more of the details.

    You need to use something like this:

    $(document).on('click', "a.myLink" function() { alert( 'Click!' ); } );
    

    or, even better use a static ancestor of your dynamic links instead of document (which I will assume here is an object #container as this will give better performance like this:

    $("#container").on('click', "a.myLink" function() { alert( 'Click!' ); } );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these two lines: $target_box.children('a.ajax_trigger_title').addClass('opened_post_title'); jQuery('#'+$target_box.attr('id')+' a.ajax_trigger_title').addClass('opened_post_title'); The first line doesn't work, but
I have the following lines of jQuery: // When dragging ends stop: function(event, ui)
I have the jQuery UI Autocomplete setup to my liking and working perfectly, but
I have this line of jQuery: $(#colorimage).css('background','url(images/bw.jpg)'); First question: the way that this is
i have a jQuery line that execute 2 animations, what i want is to
I have an Ajax contact form that links to a jquery file but for
I have commended out the problem lines so show the working code: <%@ Page
I want my text area to expand by one line only when the first
I have some lines of HTML code that are like this: <li><a href=# class=lstItem>Testing
I have a 2000 line jquery file, I just broke up the file into

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.