freelance84 Posted December 13, 2010 Share Posted December 13, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/221541-adding-and-with-classes-ids-and-js/ Share on other sites More sharing options...
freelance84 Posted December 13, 2010 Author Share Posted December 13, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/221541-adding-and-with-classes-ids-and-js/#findComment-1146821 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.