0

I'm trying to add a table using jQuery's appendTo function whenever a certain button is clicked. Here's my code:

$("#button").click(function() {
   $("#divId").dialog("open");     
   $('#divId').appendTo('.table_width');
});

Note that in this code, .table_width is the table class and #divId is the div identity. However, this does not seem to be working. Am I doing this the right way? Thanks in advance for any help.

1
  • append a class name? can you be clear on what you want to append Commented Aug 10, 2011 at 4:40

3 Answers 3

1

Use .append instead of .appendTo. What I understand from your question is that you want to append an existing table to #divId..appendTo will append your div to the table, which is not what you want.

Sign up to request clarification or add additional context in comments.

2 Comments

no i just want to add show the table and add table row to that table in the dialog box please if there is any code please help me its not working thanks in advance
I probably did not understand the question. Please provide more information.
0

Are you trying to create a whole new table on every click, or just a table row?

Anyway, you need to use "add()" to create new elements. To add a new (empty) row to an existing table, use:

$("#button").click(function() {
   $('#existing_table').add('tr').addClass('.table_width');
});

This will append a new row with the "table_width" class. Not sure if that's what you want though ;)

1 Comment

there is add item button in the dialog box on that button click i want row of the table to be added i have many codes in the net even clone in jquery
0

Something like this:

$("#button").click(function() {
   $('#divId').append($('.table_width')).dialog("open");
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.