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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:23:09+00:00 2026-06-01T04:23:09+00:00

I am trying to add a html snippet dynamically which contains named anchors and

  • 0

I am trying to add a html snippet dynamically which contains named anchors and destinations via jquery append(‘html’) method

None of the named links work after the append. The newly added content is visible on the page, but the links dont work. Is it because these tags were added dynamically, or am I doing something wrong here? However, all server side generated named anchors work fine.

simplified html:

<a href="#tab">Foo</a>

<div id="tab"></div>

("#testButton").click(function() {
   $('#mainSegmentDiv').append("html")
});
  • 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-01T04:23:10+00:00Added an answer on June 1, 2026 at 4:23 am

    Anchors appended with JavaScript should work as anchors (in that clicking them should take you to whatever location is specified in its href attribute), but if you’re trying to use an tag-name, id or class to select them, they won’t ‘work’ because they weren’t present in the DOM when the event handlers were bound:

    JS Fiddle demo (demonstrates non-working code).

    Without specific knowledge of your HTML, or what you’re doing, I can only offer you this suggestion:

    $('body').on('click','a',function(){
        // do something
    });
    

    JS Fiddle demo (demonstrates working code).

    The on() method attaches the click event (in this case) to the body element and relies on event propagation to work, in that the click bubbles up to the body and then works out where it came from and if it matches the given selector (the a in this case, you can use id, class or any valid jQuery selector). If it matches the selector the function the events/functions (in this case that’s the // do something comment) is executed.

    Ideally, instead of using the $('body') you’d use the closest parent-element to those elements you later add to the DOM that exist at the time of event-binding (usually $(document).ready()).

    References:

    • on().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add html code inside a <span id=options></span> so I'm trying to
I'm trying to add some HTML formatted text to Word using Office Interop. My
I am trying to add a .html suffix at the end of all strings
I'm trying to add overflow to an HTML element, and of course it works
I've been trying to add a swf over a swf on a html page,
I am trying to add a draggable object to to a simple html page.
I'm trying to add .css and .js file in my HTML template files that
I'm trying to add an image to a generated html word document that is
I'm trying to compare two numbers, and add an HTML class to the large
I'm trying to add some html markup to the WYSIWYG CLEditor from outside of

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.