3/20/2024 0 Comments Tabledit how to add text aboveI think the safest solution is probably to ensure your table always includes at least one tbody in your markup, even if it has no rows. You will need to make sure the jQuery code tallies with your markup. Weighing everything up, I'm not sure there is a single one-line solution that accounts for every single possible scenario. This gets around the issue of having no rows, but still isn't bulletproof as you could theoretically have multiple tbody elements and the row would get added to each of them. If you have no rows, there will be no tbody unless you have specified one yourself.ĭaRKoN_ suggests appending to the tbody rather than adding content after the last tr. eyelidlessness makes a good comment that there will always be a tbody in the DOM this is true, but only if there is at least one row. Update: Revisiting this answer following recent activity with this question. You can include anything within the after() method as long as it's valid HTML, including multiple rows as per the example above. I would therefore recommend this approach instead: $('#myTable tr:last').after('.') The approach you suggest is not guaranteed to give you the result you're looking for - what if you had a tbody for example:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |