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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:04:02+00:00 2026-06-12T10:04:02+00:00

I have added a new element via jquery. Now I want a function to

  • 0

I have added a new element via jquery. Now I want a function to trigger when the element is clicked. I know there are many answers to this, but they don’t seem to work for me. Not sure what I am doing wrong here.

I have tried:

new_ele = "<a>click me</a>"
new_ele.click(function() {alert('xxxx');}); 
other_ele.append(new_ele);

This fails before the new_ele is appended.

I have also tried (instead of the second line above)

new_ele.onclick = function() { alert('blah'); };

This appends the element, but nothing happens when I click.

And

new_ele.on('click',function() {alert('ddd');});

This also fails before the element is appended.

  • 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-12T10:04:03+00:00Added an answer on June 12, 2026 at 10:04 am

    Change it to:

    new_ele = $("<a>click me</a>");
    new_ele.click(function() {alert('xxxx');}); 
    other_ele.append(new_ele);
    

    In order to add a jQuery .click() handler, you need a jQuery object that you can call the .click() method on. Your code was trying to do:

    "<a>click me</a>".click(function() {alert('xxxx');}); 
    

    which obviously wouldn’t work because there’s no click method on a string. Instead, you need to turn that HTML string into an actual jQuery object by calling $() on it.

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

Sidebar

Related Questions

I have dynamically added an element in page using jquery with following function. function
Hello there i have written some code in jquery to add new input type
I have a table where the rows are dynamically removed and added via jQuery.
My storyboard seems locked. I have added new labels and imageviews to two different
I have added a new job in my hudson server which builds the project
I have IIS 7.5 With one web site I added new virtual directory and
Most of my content is in a new table I have added to JOOMLA
I have a list within Sharepoint, using a custom new form I have added
We recently added a new TeamCity build agent. Because it doesn't have ASP.NET MVC
I have download the new Bing API C# file and added it to my

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.