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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:55:58+00:00 2026-06-13T01:55:58+00:00

I am trying to pull out some HTML (a hrefs) from a long string

  • 0

I am trying to pull out some HTML (a hrefs) from a long string of data returned in an AJAX call from the server and then add these to the DOM, tried following several examples on the prior answers but cannot seem to get the DOM element to be clickable though it appears to be added as a link. So, have stepped back and trying to add one new element when clicking on another and can’t get this working either – have tried in jsfiddle, basic example of code is as follows below – when clicking on the getsearchresults, the a href is displayed within the searchresults div but when clicked does not fire the .clicakable_search handler.

HTML
Get search results

results

JS code

    $(document).ready(function() {
        $("#getsearchresults_id").click(function(event) {
        var aa = $('<a href="#" class="clickable_search">parsed substring from the return data</a>');
        $('#searchresults').append(aa);
    });

    $('.clickable_search').click(function(e) {
        console.log(".clickable_search");
        e.preventDefault();
        alert('anchor without a href was clicked');
    });
   });
  • 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-13T01:55:59+00:00Added an answer on June 13, 2026 at 1:55 am

    it’s because it didn’t exist in the dom at the time of binding. Delegation binds the event handler to a parent element that will in turn listen for the event as it bubbles up. Make sure the parent element is a static element

    use delegation – preferred way if using jQuery 1.7+

    $('#searchresults').on('click', '.clickable_search',function(e){ 
        console.log(".clickable_search");
        e.preventDefault();
        alert('anchor without a href was clicked');
    });​
    

    jQuery 1.7 and lower

    $('#searchresults').delegate('.clickable_search','click', function(e){ 
        console.log(".clickable_search");
        e.preventDefault();
        alert('anchor without a href was clicked');
    });​
    

    or bind after element is added to dom – this will add multiple if clicked multiple times

    $(document).ready(function() {
        $("#getsearchresults_id").click(function(event) {
            var aa = $('<a href="#" class="clickable_search">parsed substring from the return data</a>');
            $('#searchresults').append(aa);
            $('.clickable_search').click(function(e) { //< --it 's your other click function
                console.log(".clickable_search");
                e.preventDefault();
                alert('anchor without a href was clicked ');
            });
        });
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im having some difficulty trying to pull out a specific value from a cookie.
I'm trying to pull some data out of logs on remote machines using awk,
I am trying to pull out data from the table I had from the
I am trying to serialize some data from a form. The html: <form class=span5
I am trying to pull some data out of our testing database with an
I am using ajax to pull some data from a PHP script I created.
I am trying to draw a graph of some data I pull out of
I'm trying to pull out specific elements from results from the Data Science Toolkit
I'm trying to pull some data out of an OLD database that is running
I'm trying to pull out a list of table names from a MySQL database.

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.