C
C
Captain Cocoa2015-09-25 16:17:13
JavaScript
Captain Cocoa, 2015-09-25 16:17:13

How to find a parent?

In general, there is such a design.

When you hover over the red side, it expands and the right side narrows, and vice versa.
Everything works as it should.
But if you add one more of the same construction to HTML, it will also expand.
Tell me how to search for a parent, so that when hovering, only the side that the cursor is on expands, and not all that are on the page.

After all, do not write a separate script for each block.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2015-09-25
@RadCor

https://api.jquery.com/closest/
can be written more beautifully, but for an example...

$('.left').hover(function() {
    $(this).closest('.dubSec').find('.left').toggleClass('open');
    $(this).closest('.dubSec').find('.right').toggleClass('close');
});

A
Alexander Taratin, 2015-09-25
@Taraflex

Without js
https://jsfiddle.net/QW01_01/9oe4ne1t/1/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question