In this jQuery part there are many repetition and I try using loop but when I try to click a button, it gives all the buttons response at the same time. please help
$('.btn1').mouseenter(function(){
if($('.pop1').css('opacity') == "0")
$('.pop1').css('opacity','1')
})
$('.btn2').mouseenter(function(){
if($('.pop2').css('opacity') == "0")
$('.pop2').css('opacity','1')
})
$('.btn3').mouseenter(function(){
if($('.pop3').css('opacity') == "0")
$('.pop3').css('opacity','1')
})
$('.btn1').mouseleave(function(){
if($('.pop1').css('opacity') == "1")
$('.pop1').css('opacity','0')
})
$('.btn2').mouseleave(function(){
if($('.pop2').css('opacity') == "1")
$('.pop2').css('opacity','0')
})
$('.btn3').mouseleave(function(){
if($('.pop3').css('opacity') == "1")
$('.pop3').css('opacity','0')
})
2
Answers
There may be better ways using a single class and DOM navigation relative to
$(this)
. But you can also just use a loop to substitute the loop index into the class names.You need to post the HTML. If you have the buttons and the pops in two different containers you can do this