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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:48:24+00:00 2026-06-18T10:48:24+00:00

In the HTML, I have a button defined like this: <button type=button onclick=toggleEdit();>Edit</button> At

  • 0

In the HTML, I have a button defined like this:

<button type="button" onclick="toggleEdit();">Edit</button>

At the end of the page, I have this script I am working on:

<script language="JavaScript">
  <!--
  function toggleEdit() {
    var btn = $(this);
    var li = btn.parent();
    var textArea = li.children('.readOnly');
    ...
  }
  //-->
</script>

I cannot reference the button I have clicked in the script. The btn variable is an object, but I don’t know anything else than that.

I found many examples on the internet that are using this approach:

$(document).ready(function () {
   $('#buttonID').click(function () {
   ...

but I cannot reference the button via ID because it is added dynamically. So, how do I reference it? 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-06-18T10:48:25+00:00Added an answer on June 18, 2026 at 10:48 am

    Just to keep it your way, you have to tell the code that this will refer to the button instead of the actual function.

    To do this you can just add an extra argument to the toggleEdit function.

    The new HTML would look like this (no apply or call function needed):

    <button type="button" onclick="toggleEdit(this);">Edit</button>
    

    Then your new JavaScript would look like this:

    <script language="JavaScript">
      <!--
      function toggleEdit(t) {
        var btn = $(t);
        var li = btn.parent();
        var textArea = li.children('.readOnly');
        ...
      }
      //-->
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button on an html page declared like so: <button type=submit name=action
I have html markup like this <button id=button1 onclick=alert='yup'></button> and I want to make
I have a html button linked to php page. The php page calls a
i have a Button on a HTML page . i want to attach file
i have html form i am using <a href="#" onclick="document.aa.submit()"> instead of submit button
I'm adding HTML controls dynamically using java script. For instance, I have one button
I have a HTML page on click of button i am displaying a Popup
And i have this edit button : @Ajax.ActionLink( , Edit, new { oid =
I'm working on an HTML page where we would like the input fields and
see fiddle i have html table and one textbox and one button.make cell selection

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.