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
https://forums.phpfreaks.com/topic/221541-adding-and-with-classes-ids-and-js/
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>


Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.