You reattach it the same way you attack it the first time. Because you're going to be rebinding, move the stuff in the first bind (where you bind the submit action) into it's own function (outside of the $(document).ready() function, only put stuff there that you want firing when the page loads). Then do something like this:
$(document).ready(
$("#addsymbolform").bind("submit",function(){
var newSymbols = document.getElementById('newsymbol').value;
document.getElementById('newsymbol').value = '';
if(newSymbols.length > 0) {
$("tbody#stocks").load('/myurlwithparams');
$(document).ready();
}
return false;
});
var newSymbols = document.getElementById('newsymbol').value;
document.getElementById('newsymbol').value = '';
if(newSymbols.length > 0) {
$("tbody#stocks").load('/myurlwithparams');
$(document).ready();
}
return false;
});
);
becomes:
$(document).ready(
$("#addsymbolform").bind("submit",newFunc());
);
function newFunct() {
var newSymbols = document.getElementById('newsymbol').value;
document.getElementById('newsymbol').value = '';
if(newSymbols.length > 0) {
$("tbody#stocks").load('/myurlwithparams');
//$(document).ready(); <~~~~INSTEAD OF THIS:
document.getElementById('newsymbol').value = '';
if(newSymbols.length > 0) {
$("tbody#stocks").load('/myurlwithparams');
//$(document).ready(); <~~~~INSTEAD OF THIS:
$("#addsymbolform").unbind();
$("#addsymbolform").bind("submit",newFunc());
}
return false;
}
}
return false;
}
Without an example site so I can see exactly what's going wrong, that's the best I can do. Hope it helps!
On 8/15/06, Jason Huck <[EMAIL PROTECTED]> wrote:
> First off, $(document).ready() only fires once. When the document is first
> ready.
Ok, makes sense, but, how do you "reattach" updated content to your events?
> Second, if you have events on a dom object, and create an identical dom
> object, you need to reattach the events to this new dom object when it's
> created (or really, whenever) for the events to fire.
Yes, exactly. How?
> I don't even really know what you're trying to accomplish with
> $(document).bind("load",etc...);
I think I got it from the rounded corners plugin sample code, which is the
first thing I used with jquery. Sorry, what can I say, I'm just getting
started with this stuff.
> Just use
>
> $(document).ready(function(){
> code you want to happen on page load
> });
Ok, I'll make that change.
Thanks,
Jason
--
View this message in context: http://www.nabble.com/replaced-content-losing-it%27s-%27binding%27-tf2109860.html#a5823036
Sent from the JQuery forum at Nabble.com.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/
_______________________________________________ jQuery mailing list [email protected] http://jquery.com/discuss/
