So I have several items with one class, each one has a description tape with an specific name. I want to have names appeared on items on mouse hover. I did the job with jquery but the only problem is there are a lot of these items and I can't add hover function to each on using their ID. (and I feel stupid when I do so). so I'm looking for a nice clean way to merge my whole hover functions into one.
HTML CODE:
<div class="cam" id="CAM01"><div class="camD" id="CAMd01"><p>ZX-8810HD</p></div></div>
<div class="cam" id="CAM02"><div class="camD" id="CAMd02"><p>ZX-8820HD</p></div></div>
<div class="cam" id="CAM03"><div class="camD" id="CAMd03"><p>ZX-8822HD</p></div></div>
JS CODE:
$("#CAM01").hover(function() {
$("#CAMd01").css('opacity', '1');
});
$("#CAM01").mouseout(function() {
$("#CAMd01").css('opacity', '0');
});
$("#CAM02").hover(function() {
$("#CAMd02").css('opacity', '1');
});
$("#CAM02").mouseout(function() {
$("#CAMd02").css('opacity', '0');
});
$("#CAM03").hover(function() {
$("#CAMd03").css('opacity', '1');
});
$("#CAM03").mouseout(function() {
$("#CAMd03").css('opacity', '0');
});
And I'm looking for sth like this:
$(".cam").hover(function(){
if(selectedCamId == CAM03){
$("#CAMd03").css('opacity', '1');
}
});
.camD{opacity: 0}.cam:hover .camD {opacity: 1}