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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:37:45+00:00 2026-06-05T17:37:45+00:00

This is my js code: <script> function add(){ $(‘#myTable tr:last’).after(‘<tr><td>4<span onclick=del()>del row</span></td></tr>’); } function

  • 0

This is my js code:

<script>
function add(){
  $('#myTable tr:last').after('<tr><td>4<span onclick="del()">del row</span></td></tr>');
}
function del(){
  $(this).parent('tr').remove();
}
</script>

and html:

<table id="myTable" border="1">
    <tr><td>1</td></tr>
    <tr><td>2</td></tr>
    <tr><td>3</td></tr>
</table>

<span onclick="add()">add row</span>

My add button work nice but my del button not work. When del row clicked nothing happened.

  • 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-05T17:37:47+00:00Added an answer on June 5, 2026 at 5:37 pm

    Little change with your code

    function add(){
      $('#myTable tr:last').after('<tr><td>4<span onclick="del(this)">del row</span></td></tr>');
    }
        
    function del(el) {
        $(el).closest('tr').remove()
    }
    

    Working sample


    Another easier approach, not need radical change in your code

    I think more easy will be that, if you add a class to the del row span and remove onclick like following:

    function add(){
      $('#myTable tr:last').after('<tr><td>4<span class="delRow">del row</span></td></tr>');
    }
    

    and set delegate event handler like following:

    $('#myTable').on('click', 'span.delRow', del);
    

    and write your del() function like following:

    function del() {
      $(this).closest('tr').remove();
    }
    

    Working Sample


    And one important note

    Don’t forget to place your whole code within

    $(document).ready(function() {..})
    

    in short

    $(function() {..})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this code which add textbox dynamically row_no=0; function addRow(tbl,row){ row_no++; if (row_no<=20){
I have this code: <script> $(function() { $(#tabs).tabs({ event: mouseover }); $(#tabs).tabs(add,#tab-4,Friends Discussions); $(#tabs).tabs(add,#tab-5,Announcements);
This is my code and in this i wanna call a java script function
I've got this piece of code in my jquery validation script: resetForm: function() {
So I have this code: <script type=text/javascript> $(function(){ $('.content_slider').bxSlider({ pager: true, buildPager: function(slideIndex){ switch
I have this code: <script type=text/javascript> var maxLength=10; function charLimit(el) { if (el.value.length >
I have this code in userpage.php: <script langauge=JavaScript><!-- function newWindow(fileName,windowName) { msgWindow=window.open(fileName,windowName); } //--></script>
Say I have this code in my page: <script language=javascript> $(document).ready(function() { $(.test).click(function() {
I used this code for sending and returning result. <script type=text/javascript> $(document).ready(function() { $('.special').click(function(){
I have this code <html> <include jquery> <script> function crea() { var html =

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.