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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:10:30+00:00 2026-06-07T07:10:30+00:00

On a site that I’m building for someone, I am making most internal links

  • 0

On a site that I’m building for someone, I am making most internal links use pushState since it is a faster user experience. I’m having a problem with getting the href attribute from an anchor <a> element that is loaded dynamically. People always tell me to use .on() rather than .live() because .live() is deprecated, but then I run into problems like this.

Here’s my code:

$('#artists').on('click', '.artist a', function(e) {
        SM.config.loader.show();
        var href = $(this).attr('href');
        SM.loadContent(href,'artist');
        history.pushState('', 'New URL: ' + href, href);
        e.preventDefault();
});

There is no href attribute being returned (obviously) so the URL is not changing.

Basically my question is how do I get the href attribute from the element in the second parameter of the on event?

  • 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-07T07:10:33+00:00Added an answer on June 7, 2026 at 7:10 am

    This code is working for me: http://jsfiddle.net/NcZ22/2/

    HTML

    <div id="artists"></div>​
    

    JS

    //Bind an event
    $('#artists').on('click', '.artist', function(e) {
            e.preventDefault();    
            var href = $(this).attr('href');
            console.log(href);
    });​
    
    //Add the element to the dom
    $('<a />', {
        href: 'http://stackoverflow.com',
        text: 'SO',
        class: 'artist'
    }).appendTo('#artists');
    

    Also, make sure you are using jQuery 1.7+ You can read more about .on vs .delegate here http://api.jquery.com/delegate/

    Simple comparison of syntax:

    $(selector).live(events, data, handler);                // jQuery 1.3+
    $(elements).delegate(selector, events, data, handler);  // jQuery 1.4.3+
    $(elements).on(events, selector, data, handler);        // jQuery 1.7+
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a site that allows the user to download a set of
I have an intranet site that loads in IE7 compatibility mode, unless the user
I have a Django site that takes in sensitive information. I use https/SSL, so
I've got a site that's relatively simple. The user performs some action on the
I am creating a site that requires a user to add tags to their
I have a site that have URL similar to this: /mysite/admin/controller/action/id /mysite/search/controller/action/id /mysite/user/controller/action/id I
A site that links to mine keeps my site in a frame, so I
I am building a site that would benefit from users signing up. Obviously adding
I have a voting site that my users can use to promote my game.
I'm building a site that needs to work with browsers that support JavaScript and

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.