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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:27:28+00:00 2026-06-17T23:27:28+00:00

I am calling ajax via jquery in an effort to load an href. The

  • 0

I am calling ajax via jquery in an effort to load an href. The html seems to load correctly. However, the html that is loaded (href) does not actually work. Specifically, I can’t figure out why once the link loads via ajax, it doesn’t actually do anything when I click it. No errors in firebug, just dead link. Is my .on() method incorrect?

home.html

<html>
<head></head>
<body>
<div id="connections">Placeholder Text</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">
var uri='home-ajax.html'; //first find out if this is created yet   
var myVar=setInterval(function(){example_ajax_request()},8000); //to do that check for it ev. 8 sec.
function example_ajax_request() {
    $.ajax({
        type: 'GET',
        url: 'home-ajax.html', //checking
        dataType: 'html', //html is content inside home-ajax.html
            success: function() {               
                $('#connections').load('home-ajax.html'); //if home-ajax exists replace connections div with its content
                clearInterval(myVar); //stop the 8 sec. timer
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(xhr.status);
                alert(thrownError);
            }
    });

}

$('myLink').on('click', function(e) { //using .on to actively bind new href link from ajax()
    document.location.href="http://www.cnn.com";//when href with id='myLink' is clicked, go to www.cnn.com
});
</script>

</body>
</html>

home-ajax.html

<p><a href="#" id="myLink">CNN</a></p>
  • 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-17T23:27:29+00:00Added an answer on June 17, 2026 at 11:27 pm

    That element did not exist on page load, so you can’t bind a click function directly to it. You have to delegate the click to a static element.

    $(document).on('click', '#myLink', function(e){
        e.preventDefault(); // stop default action
        document.location.href="http://www.cnn.com"; //do work
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am calling pages via AJAX in jQuery. The content of these pages needs
One part of my page is being loaded via ajax using jquery. For example
I'm calling a file via jQuery's AJAX method looks like this: $is_ajax = $_REQUEST['is_ajax'];
I've got a page with multiple forms that load via ajax. Each form includes
I've got a WebMethod that I'm calling from jQuery AJAX. No matter what I
I have a script that calls a php page via jquery/ajax. The results would
I'm calling a WebMethod (ASP.NET) via AJAX (jQuery). If I create a version of
Form is dynamically loaded via ajax. After form is loaded I calling initialization of
I have a form in a jQuery tab div that is loaded with AJAX:
I have a php page that I am calling via ajax and the returned

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.