jQuery - adding checkboxes in a specific table -
i'm stuck small jquery script. want make checkboxes rows of specific table. greasemonkey script, can't edit source of site.
this how html set up:
<html> <head></head> <body> <table class = test1></table> <table class = test2></table> <table class = goal> <thead> some <tr> </thead> <tbody> here table rows want put checkboxes </tbody> </table> </body> </html>
the problem that, puts checkboxes in rows @ every "tr" can find in tables. , code:
var $ = unsafewindow.jquery $(document).ready(function (){ $("table.goal").ready(function(){ $("tbody").ready(function(){ $("tr").prepend('<td><input type="checkbox" name="x" value="y"></td>'); }); }); });
please, kind explain me, why isn't working intended? in advance.
there no need use table.ready/tbody.ready, have use descendant-selector
$(document).ready(function () { $("table.goal tbody tr").prepend('<td><input type="checkbox" name="x" value="y"></td>'); });
demo: fiddle
note: if rows created dynamically, dom manipulation need executed after tr's created
Comments
Post a Comment