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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:26:57+00:00 2026-05-22T14:26:57+00:00

I am trying to develop a plugin for jQuery. This is my first plugin,

  • 0

I am trying to develop a plugin for jQuery. This is my first plugin, and I am stuck in the initial phase.

I need to do following things: I need to find the “add row” link from the table and bind to the click event. When the link is clicked, it should add a new row by cloning the existing template row. Initially the template row is hidden.

Following is the HTML.

<table id='grid1'>
    <tr>
        <td><a href='#' id='add_row'>Add New Row</a></td>
    </tr>
    <tr>
        <td>
            <table id='data_table'>
                <tr><th>Col1</th><th>Col2</th><th>Col3</th></tr>
                <tr><td>Data1</td><td>Data2</td><td>Col3</td></tr>
                <tr id='template_row'>
                   <td><input type='text' /></td>
                   <td><input type='text' /></td>
                   <td><input type='text' /></td>
                </tr>
            </table>
        </td>
    </tr>
</table>

And my jQuery so far:

(function($) {
  $.extend($.fn, {
    editableGrid: function() {
      function addRow() {
        //code to clone here but i need the instance of main table here ie grid1
      }
      this.find('#add_row').bind("click",addRow);
    }
  });   
})(jQuery);
  • 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-22T14:26:58+00:00Added an answer on May 22, 2026 at 2:26 pm

    Going on from your current code:

    (function($) {
      $.extend($.fn, {
        editableGrid: function() {
          this.find("a.add_row").click(function () {
            var $table  = $(this).parent("table").find("table.data_table");
            var $newRow = $table.find("tr.template_row").clone();
    
            $newRow.removeClass("template_row"); // !!!
            $table.append($newRow);
            return false;
          });
        }
      });   
    })(jQuery);
    

    Notes

    • work with CSS classes instead of IDs – only that way you can have multiple “editable grids” on one page
    • there is no benefit of using bind() over using click() here
    • you can pass functions directly as arguments – no need to define them separately
    • it can improve readability/clarity to use verbose selectors ("a.add_row" is better than just ".add_row")
    • in the outer function, this refers to a jQuery object containing all matched elements, so click() binds all of them in one step.
    • in the inner function, this refers to an individual DOM element (i.e. the clicked link) – it is not a jQuery object here!
    • don’t forget to return false from the click function to prevent the browser default behavior
    • it’s useful to prepend variables with a $ to denote that they contain a jQuery object
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to develop web form using jquery. all i need is to have several
I need help with this situation... i´m trying to develop a banner rotator (full
intro Hello, I'm trying to develop some plugin or / and object in javascript,
Im trying to develop my first ASP.NET MVC web app and have run into
I'm trying to develop a JQuery plug-in that will access an outside XML feed
I am trying to develop a plugin architecture in .Net. The application will be
I am trying to develop a plugin for Ruby on Rails and came across
I'm trying to develop a plugin that shows website screenshot, when a user clicks
I am currently trying to develop a simple plugin for visual studio 2008 using
I've been trying to develop my own text editor through a eclipse plugin. I

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.