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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:46:41+00:00 2026-06-12T15:46:41+00:00

Possible Duplicate: The current element as its Event function param Would this work <script

  • 0

Possible Duplicate:
The current element as its Event function param

Would this work

<script type="text/javascript">
var foo = function(param)
{
    param.innerHTML = "Not a button";
};
</script>
<button onclick="foo(this)" id="bar">Button</button>

rather than this?

<script type="text/javascript">
var foo = function()
{
    document.getElementId("bar").innerHTML = "Not a button";
};
</script>
<button onclick="foo()" id="bar">Button</button>

And would the first method allow me to load the javascript from elsewhere to perform actions on any page element?

  • 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-12T15:46:42+00:00Added an answer on June 12, 2026 at 3:46 pm

    The code that you have would work, but is executed from the global context, which means that this refers to the global object.

    <script type="text/javascript">
    var foo = function(param) {
        param.innerHTML = "Not a button";
    };
    </script>
    <button onclick="foo(this)" id="bar">Button</button>
    

    You can also use the non-inline alternative, which attached to and executed from the specific element context which allows you to access the element from this.

    <script type="text/javascript">
    document.getElementById('bar').onclick = function() {
        this.innerHTML = "Not a button";
    };
    </script>
    <button id="bar">Button</button>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Retrieve Table Row Index of Current Row <html> <script> function addValue(a) {
Possible Duplicate: How to get current date in JavaScript I need to get todays
Possible Duplicate: get name of current PHP script in include file Can an included
Possible Duplicate: Activity not started, its current task has been brought to the front
Possible Duplicate: Growable data structure in MATLAB So in my current MATLAB script, I
Possible Duplicate: How to get current python interpreter path from inside a Python script?
Possible Duplicate: PHP: Date larger than current date I have my dates in this
Possible Duplicate: Get current URL with JavaScript? How do you get the address of
Possible Duplicate: Find location of current m-file in Matlab I would like to write
Possible Duplicate: Get Current Cursor Position I creating the button like this: button =

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.