Javascript Alterations
I Am Wanting to Adjust the Following Javascript from a Mouseover Event to a Page Load Event, However My Attempts to Do So Have So Far Failed. So to Clarify...
i am wanting to adjust the following javascript from a mouseover event to a page load event, however my attempts to do so have so far failed. So to clarify, when the page loads i want the script to activate. here is the code:
$(function() {
$('#sdt_menu2 > li').bind('mouseenter',function(){
var $elem = $(this);
$elem.find('img')
.stop(true)
.andSelf()
.find('.sdt_wrap')
.stop(true)
.andSelf()
.find('.sdt_active')
.stop(true)
.animate({'height':'45px'},300,function(){
var $sub_menu = $elem.find('.sdt_box');
if($sub_menu.length){
}
});
1 Answer
If I understood the quesiton correct, it's as easy as
$(function(){
var $elem = $(this);
$elem.find('img')
.stop(true)
.andSelf()
.find('.sdt_wrap')
.stop(true)
.andSelf()
.find('.sdt_active')
.stop(true)
.animate({'height':'45px'},300,function(){
var $sub_menu = $elem.find('.sdt_box');
if($sub_menu.length){
}
});
$(handler) (that you used already) actually is a shortcut for $(document).ready(handler).
From the jQuery Documentation on .ready():
All three of the following syntaxes are equivalent:
$( document ).ready( handler )
$().ready( handler ) (this is not recommended)
$( handler )
[Edit]: If the function should still work on $('#sdt_menu2 > li'), the $elem (is this even a valid name? Oo) has to be set to that, of course. So if that'S what you want, substitute
var $elem = $(this);
by
var $elem = $('#sdt_menu2 > li')`