E-mail List Archives
Re: Return to Top Link
From: Swift, Daniel P.
Date: Oct 17, 2018 9:49AM
- Next message: Jonathan Avila: "Re: Return to Top Link"
- Previous message: JP Jamous: "Re: Return to Top Link"
- Next message in Thread: Jonathan Avila: "Re: Return to Top Link"
- Previous message in Thread: JP Jamous: "Re: Return to Top Link"
- View all messages in this Thread
Absolutely - this code would cause a problem because the click binding function happens before the element is created (actually, before the element has the ID):
$(document).ready(function(){
$('#backToTop').click(function(){
$("#someAnchor").animate({ scrollTop: 0 }, 900).attr("tabindex","0").focus();
return false;});
});
$('main').attr('id', 'someAnchor');
});
The above example is pretty silly, but it illustrates the flaw in the click binding occurring before the element exists. Specifically, it is trying to bind the click destination to the element whose ID does not exist yet.
We ended up delaying the binding by using the set timeout function which was far from elegant. IMO, a better solution would've been using a loop to check for the existence of the object and then create the binding once it's found.
Does that make sense?
Dan Swift
Senior Web Specialist
Enterprise Services
West Chester University
610.738.0589
- Next message: Jonathan Avila: "Re: Return to Top Link"
- Previous message: JP Jamous: "Re: Return to Top Link"
- Next message in Thread: Jonathan Avila: "Re: Return to Top Link"
- Previous message in Thread: JP Jamous: "Re: Return to Top Link"
- View all messages in this Thread