if condition working but else condition not working.
(function($){$(".single-product a").on("click", function(e){
var link = $(".single-product a").attr("href");
if(link == "#"){
e.preventDefault();
}else{
return true;
}
});
}(jQuery));
have you tried this? using prop on the attr it might be your jquery library is higher
$(document).on("click",".single-product a", function(e){
var link = $.trim($(this).prop("href"));
(link == "#") ? e.preventDefault() : '';
});
With the attribute contains selector [name*=”value”]
:
$('.single-product a[href*="#"]').on('click', function (e) {
e.preventDefault();
});
<div class="single-product">
<a href="https://www.google.com#foo">With #</a>
</div>
<div class="single-product">
<a href="https://www.google.com">Without #</a>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>