javascript - Return False being ignored -
any ideas why "return false" in below being ignored , opening url pages in new window? on click external url should loaded content div.
my html:
<div id="maincontainer"> <div id="mainnav"> <a class="menuitem" id="home" href="#">home</a> <a class="menuitem" id="about" href="about.html">about</a> <a class="menuitem" id="contact" href="contact.html">contact</a> </div> <div id="content"></div> <div id="footer"> <p><a class="menuitem" id="find" href="find.html">find...</a></p> </div> </div> </div>
my script:
$('#home a').click(function(){ $("#content").hide(); $("#slider1_container").fadein(); }); $('#about a').click(function() { $("#slider1_container, #contact, #find").hide(); var url=$(this).attr('href'); $('#content').load(url); return false; }); $('#contact a').click(function() { $("#slider1_container, #about, #find").hide(); var url=$(this).attr('href'); $('#content').load(url); return false; }); $('#find a').click(function() { $("#slider1_container, #about, #contact").hide(); var url=$(this).attr('href'); $('#content').load(url); return false; });
your #home
, #about
, , #contact
elements don't have descendant a
element, selectors incorrect , event isn't being hooked @ all. change $("#home a")
$("#home")
(and same about
, contact
).
side note: can condense last 3 click
handlers, same thing difference being element not hidden:
$('#home a').click(function(){ $("#content").hide(); $("#slider1_container").fadein(); }); $("#about, #contact, #find").click(function() { $("#slider1_container, #about, #contact, #find").not(this).hide(); var url=$(this).attr('href'); $('#content').load(url); return false; });
note use of .not(this)
avoid hiding current element.
Comments
Post a Comment