I have a javascript function that selects several elements, and then performs some DOM manipulation. When the DOM manipulation involves adding more elements that match the initial selectors, I'd like to re-apply them to include the new elements.
var row1 = table.find("tr.row1 td");
var row2 = table.find("tr.row2 td");
var row3 = table.find("tr.row3 td");
for(...) {
if() {//Some condition is met
table.children().each(function(row) {
row.append(row.children().eq(5).clone());
});
row1.refresh(); // I'd like something here like refresh, rather than row1 = table.find("tr.row1 td");
}
//Code that uses row1, row2, and row3
}
Is there a function that does what I'm looking for on the refresh()
line?
There isn't really a function that does what you've described, you just re-issue the original request.
If you have a jQuery object (like your row1
), you can use this undocumented mechanism to re-run the original request:
row1 = $(row1.selector, row1.context);
...but again, the selector
property is undocumented (context
is documented) and so while it works now in 1.7.1, it may well not work in 1.7.2.
A better approach may be to only keep hold of the jQuery object for the rows as long as you're actually doing something with it, but it depends on the cost of re-acquiring the list and how frequently you do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With