Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having javascript act on only one item in a list

I have the following code (coffeescript) and I have rails creating a list of subscription-videos and I want the popup to only popup on the one I hover over. But since since every video in the list has the class subscription-video no matter which I hover over it only shows the popup for the first one. What is the best way to have javascript define that I am looking for the popup id in the currently selected (one I am hovering over) subscription-video class?

$(document).ready ->
  $('.subscription-video').hover (->
    $('#popup').show()
  ), ->
    $('#popup').hide()
like image 487
Alex Avatar asked Nov 19 '25 06:11

Alex


1 Answers

You could do it with DOM traversal. Assuming your subscription-video tag and popup are in the same div:

$(document).ready ->
  $('.subscription-video').hover (->
    $(this).closest('.popup').show()
  ), ->
    $(this).closest('.popup').hide()
like image 141
jpriebe Avatar answered Nov 21 '25 20:11

jpriebe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!