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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:23:24+00:00 2026-05-31T20:23:24+00:00

Suppose I have this jQuery code. $(document).delegate(‘a[title]’, ‘click’, function(event) { var txt = //

  • 0

Suppose I have this jQuery code.

$(document).delegate('a[title]', 'click', function(event) {
       var txt = // href value of the link ;
       alert("txt");
})

How do I obtain the value of the href attribute of the link? I cannot use $(this) because that would refer to $(document).

  • 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-31T20:23:25+00:00Added an answer on May 31, 2026 at 8:23 pm

    better use .on() from jQuery (1.7+) since .delegate(), .bind() and .live() will be deprecated.

    DEMO

    //literally: bind to "document" a "click" handler for "a"
    $(document).on('click', 'a', function(event) {
        var txt = this.href;  //or $(this).attr('href');
        alert(txt);
    })
    

    ideally, you would want to bind the handler to the nearest common parent of all the elements you want affected. binding it to document is a long distance call from element, which can incur serious performance penalties.


    • jQuery deprecated .live() and advises to use .on()

    As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live().

    • jQuery superseded .delegate()

    As of jQuery 1.7, .delegate() has been superseded by the .on() method. For earlier versions, however, it remains the most effective means to use event delegation.

    • As of 1.7, jQuery prefers .on() over .bind() for flexible handling:

    As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document. For earlier versions, the .bind() method is used for attaching an event handler directly to elements. Handlers are attached to the currently selected elements in the jQuery object, so those elements must exist at the point the call to .bind() occurs. For more flexible event binding, see the discussion of event delegation in .on() or .delegate().

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

Sidebar

Related Questions

I have right now this code: <ul><li class=listitem>text<li></ul> jQuery: $('.listitem').click(function() { $(#elname).text($(this).text()); $('#slists').css('visibility','hidden') $('#elname').css('visibility','visible')
I have this piece of code written in jQuery and PHP: <script type=text/javascript> $(document).ready(function(){
Suppose I have this code: var myArray = new Object(); myArray["firstname"] = "Bob"; myArray["lastname"]
Suppose I have this code : <head> <script type=text/javascript> func1(); </script> <script type=text/javascript src=jquery.js></script>
I have this jquery script which suppose to hide/show div element base on the
Suppose I have this image: <img src=images/01.jpg border=0 rel=shadow /> Then with jQuery, I
Suppose I have this (C++ or maybe C) code: vector<int> my_vector; for (int i
Suppose I have this function: void my_test() { A a1 = A_factory_func(); A a2(A_factory_func());
Suppose I have a class like this: function myClass(q) { this.someFunction = function(e) {
Here is my jquery code: $(document).ready(function() { if ($('#login').length == 0) { $('#login').css('background', url('/css/login-bg.gif')

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.