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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:51:12+00:00 2026-06-15T21:51:12+00:00

I have HTML that I’m inserting dynamically via jQuery It is a bunch of

  • 0

I have HTML that I’m inserting dynamically via jQuery

It is a bunch of <p> tags that I want to handle on click.

However the .click completely ignores these tags.

Here’s an exmple of what I’m trying to do

http://jsfiddle.net/cjds/tc2ty/1/

UPDATE

Okay the click is working but I still have a problem with the theory.

NOTE: The issue is that this data will come in after sometime because its fetched via AJAX. Also its likely to change.

So switching the order while correct in the example will not provide solution in the actual application. Any suggestions on how to set a click event for an element that’s not yet present?

  • 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-15T21:51:13+00:00Added an answer on June 15, 2026 at 9:51 pm

    There are few problems with your code. First, you’re duplicating an element with the same id, and ids should unique. Then the problem you’re experiencing is because you’re not delegating the click event. When you create a new dynamic element the events that were previously set are not added to the new elements. There are a few ways to make this work.

    You can cache the element and add the click event to it before appending it to the DOM:

    var $p = $('<p class="reqImg">Random Data</p>').click(function(){ ... });
                 --^-- a class not an id
    

    Or you can attach the events with delegation by using the on method on the closest static parent, that is your wrapper in this case:

    $('#wrapper').on('click', 'p.reqImg', function(){ 
      console.log('Testing for click'); 
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have html that is dynamically created when I bind my gridview to a
I have html email that I would like to track click activity. I need
I have some html that is inserted dynamically with javascript. I have position:absolute; so
I have html that has 2 divs with the same id's in jquery i
I have html that looks like <tr> <td align=left><a target=_blank href=/tags/ref_color_tryit.asp?color=Yellow>Yellow</a>&nbsp;</td> <td align=left><a target=_blank
I have sample HTML that I have marked up with some special tags that
I am using jquery validation plugin. I have an html that looks like: <h2>Select
I have a page ' foo.html ' that populates a table via AJAX 'ajax.html?options=option1'
I have html that looks something like this: <div> <table> <tr onclick=show();> <td class=cell>Click
I have a string of HTML that I use as jQuery input document. //

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.