Jump to content

adding <tr> and<td> with classes, id's and js


freelance84

Recommended Posts

 

Hi,

 

I have been looking and have found several example scripts adding a new <tr> to a table: eg http://javascript.internet.com/miscellaneous/add-a-row.html

 

However from this script and ones similar i can't seem to add anything other than the content of the <td>.

 

Does anyone know how to add a <tr> with a class and id. Also at the same time adding <td>'s to the said row with classes id's and javascript?

 

I feel like i've trolling around for a while but not getting anywhere.

 

If you can give me any tips or pointers or even how to do it that would be awesome

Link to comment
Share on other sites

Hmm, well i think i've found what i'm looking for at last but now i can't figure how to add content remotely to the function.

 

Ideally i want to be able to pass a few variables to the addRow function (a class name, an id, some content for the td)

 

(i'm now using jquery)

 

<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>Modifying Table Cell Content</TITLE>
<script src="/jquery/jquery.js"></script>
<script src="/jquery/jquery.tablednd_0_5.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    // Initialise the table
    $("#table-1").tableDnD();
});
function addRow(){
  $('#table-1 tr:last').after("<tr><td colspan='3'>some more content</td></tr>");
}
</script>

</HEAD>
<BODY>
<table id="table-1" cellspacing="0" cellpadding="2">
    <tr id="1"><td>1</td><td>One</td><td>some text</td></tr>

    <tr id="2"><td>2</td><td>Two</td><td>some text</td></tr>
    <tr id="3"><td>3</td><td>Three</td><td>some text</td></tr>
    <tr id="4"><td>4</td><td>Four</td><td>some text</td></tr>
</table>
<br/><br/>
<input type="submit" name="add" value="add" onClick="addRow();"/>

</BODY>
</HTML>


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.