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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:36:07+00:00 2026-06-16T04:36:07+00:00

How can we attach a Jquery function to a div that has been appended

  • 0

How can we attach a Jquery function to a div that has been appended after the page was loaded, without any event being triggered.

In the example below defaultTab-28 is the div that has been appended later to the page.

<a href="javascript:toggleDiv('defaultTab-28')" 

and now I want to use toggle function on the “defaultTab-28” div like

function toggleDiv(divId){
     $("#" + divId).toggle();
}

If I use .delegate() or .on() I will have to specify the event like click etc, but in this case event trigger is not necessary.

Edit: to be a more precise:

I know using inline JS is not good when using JQuery, I could have used button click function from JQuery, but my question is : Is there any function like .on or .delegate to assign a function without an event

  1. I have added a div to an existing page
  2. When anybody clicks the tag I want the div that is passed to the javascript function which here is my div to use jquery toggle , but because this div is added later it cannot bind to toggle function
  • 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-16T04:36:08+00:00Added an answer on June 16, 2026 at 4:36 am

    Your code already works as is, you don’t need to do anything about the div not existing yet.

    http://jsfiddle.net/97GZb/

    function toggleDiv(id){
        $("#" + id).toggle();
    }
    
    setTimeout(function(){
        $("body").append("<div id='defaultTab-28'>I'm the div!!!</div>");
    },5000);
    

    with this html:

    <a href="javascript:toggleDiv('defaultTab-28')">Click me to toggle the div that will be appended in 5 seconds.</a> ​
    

    And to answer your comment:

    I know using inline JS is not good when using JQuery, I could have used button click function from JQuery, but my question is : Is there any function like .on or .delegate to assign a function without an event

    No, there has to be an event of some kind to tell the javascript engine when to run the code. An element being added to the page is an Event, it is called a Mutation Event. there are also Mutation Observers that can handle this as well that were meant to be a replacement for Mutation Events. Neither of the two have very good cross-browser support.

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

Sidebar

Related Questions

Does jquery/javascript have any event model that you can attach to your objects? Basically
I can see how to attach an event to an object that has no
I read that the new delegate method can attach more than one event to
I'm trying to use JQuery's on() function to attach an event to a button
I known that with subversion you can attach arbitrary properties to each files. In
Can an attacker attach a debugger to my app after installing it to the
I'm trying to attach a click function that adds a CSS class to all
I'm writing a class that needs to attach event listeners to objects within a
Can anyone tell me why this might not work Drupal.behaviors.toggleGroups = { attach:function(context, settings)
There are many ways by which we can attach an event on an HTML

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.