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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:14:45+00:00 2026-05-30T19:14:45+00:00

I had the following JavaScript code and it worked correctly – var changeImageButton =

  • 0

I had the following JavaScript code and it worked correctly –

var changeImageButton = document.getElementById("changeImageButton");
changeImageButton.onclick = buttonWasClicked;

‘buttonWasClicked’ is the name of the JavaScript function that gets called when the “changeImageButton” is clicked.

Now, I want to write the same code using JQuery. So I wrote –

 $("#changeImageButton").attr("onclick","buttonWasClicked");

But it is not working. What am I doing wrong?

  • 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-30T19:14:47+00:00Added an answer on May 30, 2026 at 7:14 pm

    You can achieve this using a few different methods

    $("#changeImageButton").click(function(){ do_something(); });
    
    $("#changeImageButton").on("click mouseover", function(){ do_something(); });
    //this is useful because you can specify more than one event, if you want to
    //(so, this code would also trigger when you move the mouse over - not what
    // you want, but just for demonstration purposes)
    
    //In jQuery 1.7+ this is doubly useful, because this will also work with elements
    //added _after_ the DOM has initially loaded and this code has run
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following javascript code: if (url.match(/?rows.*?(?=\&)|.*/g)){ urlset= url.replace(/?rows.*?(?=\&)|.*/g,rows=+document.getElementById('rowcount').value); }else{ urlset= url+&rows=+document.getElementById('rowcount').value; }
I had the following: <script type=text/javascript> var noteid = $('#noteid').val(); </script> <input type=hidden name=noteid
Given the the following javascript function, function switch_plug_drop_down(plug_id) { selector = document.getElementById('group_1'); if (plug_id
I have the following code for a fade animation in Javascript: var ticks =
I'm loading third party webpage that contains following code <script type=text/javascript> onDomReady(function() { some_code1;
I had the following in the <head> of a GSP <script type=text/javascript> $(button.remove-item).click(function() {
I had the following line snippet of code that searches for a propery of
Say I had the following code: % Cellmode_subfunction_test.m %% Cell 1 foo(1); %% Cell
If I had to following file on my development branch: # file.rb class Code
A coworker showed me the following code and asked me why it worked. <span

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.