I have a issue that I can't figure out for days now. I have two elements, logo & "Go Back" button in my header.
Now, I want those two elements to do exactly the same thing. On click, show the same drop down. I don't want to replicate my code so I am trying to move the element and assign correct classes on click.
I managed to move my element on click properly, however on one element the display: none is not changing and I am really confused why not.
I want the drop down to appear under the element that was clicked. So, if you click the "logo", the drop-down will be moved to "logo" element and will appear under the logo, if the "go back" is clicked, the drop-down will be moved to "go back" element and appear under that element.
On click, the elements change so they look exactly the same, however, the display: none property wont change on the "Go back" element. Can anyone tell me why?
jQuery("#checkout-header-count").click(function() {
jQuery("#checkout-header-logo").removeClass("checkout-prepend-dropdown");
jQuery("#checkout-header-count").addClass("checkout-prepend-dropdown");
jQuery(".checkout-prepend-dropdown-content").appendTo(jQuery("#checkout-header-count"));
});
jQuery("#checkout-header-logo").click(function() {
jQuery("#checkout-header-count").removeClass("checkout-prepend-dropdown");
jQuery("#checkout-header-logo").addClass("checkout-prepend-dropdown");
jQuery(".checkout-prepend-dropdown-content").appendTo(jQuery("#checkout-header-logo"));
});
jQuery(".checkout-prepend-dropdown").click(function() {
if (jQuery(".checkout-prepend-dropdown-content").css('display') == 'block') {
jQuery(".checkout-prepend-dropdown-content").css("display", "none")
} else if (jQuery(".checkout-prepend-dropdown-content").css('display') == 'none') {
jQuery(".checkout-prepend-dropdown-content").css("display", "block");
}
});
jQuery('.checkout-prepend-dropdown-content').click(function(e) {
e.stopPropagation();
});
jQuery(".checkout-prepend-dropdown").click(function(e) {
e.preventDefault();
e.stopPropagation();
jQuery('.checkout-prepend-dropdown-content').show();
});
jQuery(document).click(function(e) {
jQuery('.checkout-prepend-dropdown-content').hide();
});
jQuery("#returnCheckout").click(function() {
jQuery('.checkout-prepend-dropdown-content').hide();
});
.checkout-prepend-dropdown-content {
display: none;
position: absolute;
text-align: center;
background-color: #4E4D4D;
color: white;
left: -70px;
padding: 10px;
z-index: 20;
}
.checkout-prepend-dropdown-content>div {
display: inline-block;
}
.checkout-prepend-dropdown-content>div>a {
color: #9C2CA8;
}
.checkout-prepend-dropdown-content>div>a:hover {
color: white !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<div class="checkout-prepend-wrapper">
<div style="display: inline-block; padding: 0 100px;" id="checkout-header-logo" class="checkout-prepend-dropdown">
<img src="/media/logo/stores/1/logo_vv.png" alt="Logo" />
<div class="checkout-prepend-dropdown-content">
<p>Warning! You are about to leave the checkout!</p>
<div id="returnCheckout" class="vvButton">Return to checkout</div>
<div class="vvButton"><a href="/checkout/cart">Go back to basket</a></div>
</div>
</div>
<div style="display: inline-block; padding: 0 100px;" id="checkout-header-count">Go back</div>
</div>