Unable to click on toggle dropdown link
I'm having trouble with the shopping cart toggle drop down, When I click the drop down the link doesn't take me to the link location but does on everything else.
Here is my coding, am i doing anything wrong? Any help would be great.
$(document).ready(function(){
// Drop Menu
$('.navigation > ul > li > a').click(function(e){
if($(this).parent().hasClass('current')){
$(this).parent().removeClass('current');
}else{
$(this).parent().addClass('current');
}
if($(this).parent().find('ul')){
e.preventDefault();
}
});
$('.shoppingbasket > ul > li').click(function(e){
if($(this).hasClass('current')){
$(this).removeClass('current');
}else{
$(this).addClass('current');
}
if($(this).parent().find('ul')){
开发者_开发知识库e.preventDefault();
}
});
$(".navigation ul ul, .shoppingbasket ul ul").css({display: "none"});
$(".navigation ul li, .shoppingbasket ul li").click(function(){
$(this).find('ul:first').slideToggle(400);
});
});
There are few issues in your code, try this
$(document).ready(function(){
// Drop Menu
$('.navigation > ul > li > a').click(function(e){
var $parent = $(this).parent();
if($parent.hasClass('current')){
$parent.removeClass('current');
}else{
$parent.addClass('current');
}
if($parent.find('ul').length > 0){
e.preventDefault();
}
});
$('.shoppingbasket > ul > li').click(function(e){
var $this = $(this);
if($this.hasClass('current')){
$this.removeClass('current');
}else{
$this.addClass('current');
}
if($this.parent().find('ul').length){
e.preventDefault();
}
});
//This will stop the event propagation from sub menus
$('ul.sub-menu').click(function(e){
e.stopPropagation();
});
$(".navigation ul ul, .shoppingbasket ul ul").css({display: "none"});
$(".navigation ul li, .shoppingbasket ul li").click(function(){
$(this).find('ul:first').slideToggle(400);
});
});
In your markup for the shopping cart links the only thing I see different than the other links is a target attribute.
<a class="visitshop" title="Visit Shop" href="http://www.media21a.co.uk/clientlogin/benaiahmatheson/products-page/" target="_parent">Visit the shop</a>
Try removing this attribute:
target="_parent"
精彩评论