Reputation: 1601
I've got a working slideDown div in profile.php. When I click the Users Name the profile information dives slides down. Here is the structure,
profile.php - This works fine.
$('.showprofile').click(function() {
$('#userprofile').slideDown(1000);
});
Where I am stuck is,
I want to have a link on users.php
<a href='profile.php#userprofile'>
when I click on the above link I should be taken to the profile.php page and then the userprofile div should slide down automatically.
How can i achieve this?
Upvotes: 1
Views: 121
Reputation: 85545
You should use window.load() function for that. Then when the page loads the scrip is called.
$(window).load(function(){
$('.showprofile').click(function() {
$('#userprofile').slideDown(1000);
});
});
As per your comment: Try this::
var pathname = window.location.href.substring(window.location.href.lastIndexOf('/') + 1);
if(pathname='users.php'){
$(window).load(function(){
$('.showprofile').click(function() {
$('#userprofile').slideDown(1000);
});
});
});
}else if{
$('.showprofile').click(function() {
$('#userprofile').slideDown(1000);
});
}
Upvotes: 2
Reputation: 67207
Just add that code inside of $(window).load()
of that page,
<script>
$(document).ready(function(){
$(window).load(function(){
$('#userprofile').slideDown(1000);
});
});
</script>
Note that, You should register window.load()
inside document.ready()
, Because There may be chances of the element with id #userprofile
will not be available after the page loads.
Upvotes: 3