Using javascript for only one item in a list
I have the following code (coffeescript) and I have rails creating a list of subscribed videos and I want the popup to only appear in the one I hover over. But since, since every video in the list has a class video subscription, no matter which course I am on, only the popup for the first is shown. What is the best way to define javascript in that I am looking for a popup id in the currently selected class (the class that I hover over the caption)?
$(document).ready ->
$('.subscription-video').hover (->
$('#popup').show()
), ->
$('#popup').hide()
+3
source to share
2 answers
Since you are using jQuery, you can try this:
$(document).ready(function(){
$(document)
.on("mouseenter",".subscription-video", function(e){
$(e.target).hide(300);
});
$(document)
.on("mouseleave",".subscription-video", function(e){
$(e.target).show(300);
});
});
Also known as event delegation
+1
source to share