Forum Moderators: open
var t = $(opts.newRow).find("td").wrapInner("<div style='display:none;'/>").parent() var t = $(opts.newRow).find("#Demo3 > tbody > tr > td").wrapInner("<div style='display:none;'/>").parent() <html>
<head></head>
<body>
<button type="button" id="addRowDemo3">Add a row</button>
<button type="button" id="removeRowDemo3">Remove a row</button>
<table id="Demo3" name="Demo3" class="rounded-corner" summary="Anirows Demo 1">
<thead>
<tr>
<th scope="col" class="rounded-company">Number</th>
<th scope="col" class="rounded-q1">Topic</th>
<th scope="col" class="rounded-q2">Sub Topic</th>
<th scope="col" class="rounded-q3">Lecture Notes</th>
<th scope="col" class="rounded-q4">Action</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="4" class="rounded-foot-left" style="border-right: 0px solid #fff;"><em>This is the footer, notice the plugin skips over it.</em></td>
<td class="rounded-foot-right"> </td>
</tr>
</tfoot>
<tbody>
<tr id = "newRow">
<td> </td>
<td> <textarea></textarea></td>
<td> <textarea></textarea></td>
<td>
<table id="Demo4" name="Demo4">
<tbody>
<tr>
<td>Grades</td>
</tr>
</tbody>
</table>
</td>
<td> </td>
</tr>
</tbody>
</table>
</body>
</html>
(function ($) {
var defaults = {
rowSpeed: 300,
newRow: null,
addTop: true,
removeTop: true
};
var newClasses = "newRow"
var options = $.extend(defaults, options);
$.fn.addRow = function (options) {
opts = $.extend(defaults, options);
var $table = $(this);
var $tableBody = $("tbody", $table);
var t = $(opts.newRow).find("td").wrapInner("<div style='display:none;'/>").parent()
if (opts.addTop) t.appendTo($tableBody);
else t.prependTo($tableBody);
t.attr("class", newClasses).removeAttr("id").show().find("td div").slideDown(options.rowSpeed, function (){
$(this).each(function () {
var $set = jQuery(this);
$set.replaceWith($set.contents());
}).end()
})
var id1 = $('div1').attr('id');
$("div1").replaceWith($('<div id="'+id1+'"/>').html($('div1').html()));
var id2 = $('div2').attr('id');
$("div2").replaceWith($('<div id="'+id2+'"/>').html($('div2').html()));
var id3 = $('div3').attr('id');
$("div3").replaceWith($('<div id="'+id3+'"/>').html($('div3').html()));
return false;
};
$.fn.removeRow = function (options) {
opts = $.extend(defaults, options);
var $table = $(this);
var t
if (opts.removeTop) t = $table.find('tbody tr:last')
else t = $table.find('tbody tr:first');
t.find("td")
.wrapInner("<div style='DISPLAY: block'/>")
.parent().find("td div")
.slideUp(opts.rowSpeed, function () {
$(this).parent().parent().remove();
});
return false;
};
return this;
})(jQuery);
$(opts.newRow) find("td")] seems to find any td's and then wrapInner of the parent [ tr]. Is that correct? var t = $(opts.newRow).find("td").wrapInner("<div style='display:none;'/>").parent()
if (opts.addTop) t.appendTo($tableBody);
else t.prependTo($tableBody); var t = $(opts.newRow).children("td").wrapInner("<div style='display:none;'/>").parent()
if (opts.removeTop)t=$table.children('tbody tr:last')
else t=$table.children('tbody tr:first')
if (opts.removeTop)t=$table.children('tbody tr:last')
else t=$table.children('tbody tr:first')