Try to do:
$(".wishlist-icon").click(function() {
if($(this).data('wish-name') == "product") {
$(this).hide();
}
});
题
I have the following code:
$(".wishlist-icon").click(function() {
$(".wishlist-icon[data-wish-name='product']").hide();
});
I wan't to change the selector inside the function to "this", but it's not working for me. How should I type it out?
So if "this" has data-wish-name='product', then hide it.
解决方案
Try to do:
$(".wishlist-icon").click(function() {
if($(this).data('wish-name') == "product") {
$(this).hide();
}
});
其他提示
you can do in two ways:
1)
$(".wishlist-icon").click(function() {
if($(this).attr('data-wish-name') == "product") {
$(this).hide();
}
});
2)
$(".wishlist-icon").click(function() {
if($(this).data('wish-name') == "product") {
$(this).hide();
}
});
Try this:
$(".wishlist-icon").click(function() {
$(this).find("[data-wish-name='product']").hide();
});