M
M
Maxim2015-09-30 16:21:22
JavaScript
Maxim, 2015-09-30 16:21:22

Selector data attribute?

There are n-th number of such blocks, at least 20 pieces, and it is not correct to describe hover for each separately,
the question is the following. How can I show the corresponding main_calendar when hovering over month_block ?

<div class="month_block" data-idboard="id_1"> </div>
       <div class="main_calendar" data-idboard="id_1"></div>

 <div class="month_block" data-idboard="id_2"> </div>
       <div class="main_calendar" data-idboard="id_2"></div>

 <div class="month_block" data-idboard="id_3"> </div>
       <div class="main_calendar" data-idboard="id_3"></div>

... ... ...
and so on

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivan Antonov, 2015-09-30
@kisliymaxim

jsfiddle.net/u6wyycqg

$('.month_block').hover(function() {
    var idboard = $(this).attr('data-idboard');
    $('.main_calendar[data-idboard="' + idboard +'"]').slideToggle(200);
});

D
Dmitry Korolev, 2015-09-30
@Apathetic

css

.month_block:hover + .main_calendar,
.main_calendar:hover {
    display: block;
}

The second selector (.main_calendar:hover) is added for good UX, you can not use it, of course.
JS:
$('.main_calendar').hover(function() {
    var idboard = $(this).data('idboard');
    $('[data-idboard="' + idboard + '"]').slideToggle(200);
});

D
Dmitry Pyrkin, 2015-09-30
@ps1panda

$('.month_block').mouseover(function(){
$(this).children().show()
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question