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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:17:53+00:00 2026-06-18T08:17:53+00:00

I want to change the button onclick function inside a div. The HTML code

  • 0

I want to change the button onclick function inside a div. The HTML code is as bellow

<div class="buttons-set" id="payment-buttons-container">
    <button type="button" class="button" onclick="payment.save()" id="payment_button"></button>
</div>

I am using the following prototype to change the onlick function payment.save() to something else.

if(payment_method=='gate') {
   var e = $$('div#payment-buttons-container button.button');
   e.setAttribute('onclick','return false;'); // not working
} else {
    var e = $$('div#payment-buttons-container button.button');
    e.setAttribute('onclick','payment.save();'); // not working
}

Which is not working and saying “Uncaught TypeError: Object [object HTMLButtonElement] has no method ‘setAttribute'”But when i am using this code by taking the id of the button statically, than its working

if(payment_method=='gate') {
    $('payment_button').setAttribute('onclick','return false;');// Works
}
else {
    $('payment_button').setAttribute('onclick','payment.save();');// Works
}

Where “payment_button” is the ID of the button which i taken.

  • 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-18T08:17:54+00:00Added an answer on June 18, 2026 at 8:17 am

    The problem is that $$() returns a list of elements that match the CSS selector

    try this if you just want the first element the matches the selector

    if(payment_method=='gate') {
       var e = $$('div#payment-buttons-container button.button')[0];
       e.setAttribute('onclick','return false;'); // not working
    } else {
       var e = $$('div#payment-buttons-container button.button')[0];
       e.setAttribute('onclick','payment.save();'); // not working
    }
    

    if you want to apply it to all the elements that the CSS selector matches do it this way using the invoke() method

    if(payment_method=='gate') {
       $$('div#payment-buttons-container button.button').invoke('writeAttribute','onclick','return false;');
    } else {
        $$('div#payment-buttons-container button.button').invoke('writeAttribute','onclick','payment.save();'); // not working
    }
    

    the reason I used writeAttribute() instead of setAttribute() is that writeAttribute() is the PrototypeJS method and will work across all the browsers that PrototypeJS supports, setAttbribute() is the standard method that is not always available.

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

Sidebar

Related Questions

I have a link button that I want to change it onclick callback function
I am using prototype to change the onclick function of the button. The following
i want change the content of a UITableView when i change a button, how
I want to change a button color in my app by selecting color. Instead
I want to change the button content depending on the previous content click. For
I want to change my radio button text in android app with a value
I have a RadioButtnList. I want change body background color based on radio button
I want to change content of a Button in XAML using a DataTrigger. Conditionally
I want to change the name of enter button (the button circled in the
I want to change data on listview runtime after button click... here is 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.