Fade in jquery load call -
i have basic question jquery. don't know how that's why i'm here looking help. code:
edit: <a href="javascript:$('#target').load('page.html').fadein('1000');">link</a>
as see want load page.html div called #target. want wich doesen't work make page.html fade in when loads. what's right way that?
best regards
first, should put javascript code outside element itself. simple do. makes html , javascript more comprehensible , allows more organised code. first, give a
element id
:
<a href='#' id='loadpage'>link</a>
then make call in script
tag:
<script type="text/javascript"> $(document).ready(function() { // when whole dom has loaded $('#loadpage').click(function(){ // bind handler clicks on #loadpage $('#target') .hide() // make sure #target starts hidden .load('page.html', function() { $(this).fadein(1000); // when page.html has loaded, fade #target in }); }); }); </script>
edit comment, yes can use url in a
tag , use this.href
.
<a href='page.html' id='loadpage'>link</a> <script type="text/javascript"> $(document).ready(function() { $('#loadpage').click(function(e){ e.preventdefault(); $('#target') .hide() .load(this.href, function() { $(this).fadein(1000); }); }); }); </script>
Comments
Post a Comment