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

  • Home
  • SEARCH
  • 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 6469123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:57:17+00:00 2026-05-25T05:57:17+00:00

I create a anchor using jQuery and the onclick event seems be triggered when

  • 0

I create a anchor using jQuery and the onclick event seems be triggered when the element is created. I’ve used this method of creating elements a few times with this project without a problem, have I got the wrong end of the stick?

jQuery('<a/>', {
    href: '#',
    name: 'link_html_edit',
    id: 'link_html_edit',
    html: 'input HTML text',
    onclick: alert('test')
}).appendTo(spanDefaultValue);

Thanks

  • 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-05-25T05:57:17+00:00Added an answer on May 25, 2026 at 5:57 am

    You’re calling alert('test'); and assigning it’s return value to onclick. Use this instead:

    onclick: function(){ alert('test'); }
    

    Since I’m sure alert('test') is just an example I should also point out that if you have the same problem with some function you likely can just change your code from:

    onclick: somefunction()
    

    To:

    onclick: somefunction
    

    You only need to wrap it in an anonymous function the way I did with alert('test'); if you’re passing arguments to the function other than the event object that is normally passed to an event handler.

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

Sidebar

Related Questions

I created an anchor like this: <a id=create /> and it works in IE
I am using jQuery to create an anchor and bind it with JavaScript function
I am dynamically generating an anchor tag using jQuery. I have added an onclick
I'm using this jquery http://css-tricks.com/examples/SmoothPageScroll/ to create a smooth page scroll, however each time
I am trying to create a menu using anchor tags, and they should butt
I'm using JQuery to create a Horizontal Accordion menu (based on the tutorial at
I have created a fake file input using an anchor tag and placed a
I've created a page using JQuery and Ajax that helps a user filter through
Is it possible to apply / create a YUI Button by using an element's
I've created a list item element that contains a child anchor element. <ul id=machine-list>

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.