문제

I want all links with class play to show the one and only video element present in their container.

The simplified HTML looks like this:

<div>
    <a class="play">Play</a>
    <video>…</video>
</div>            

And I'm thinking along these lines for the jQuery, but don't understand how to target an element inside of parent:

$('.play').click(function(e){
    e.preventDefault();
    var target = $(this).parent().$('video');
    t.show();
})
도움이 되었습니까?

해결책

You can use:

$(this).parent().find('video:first');

OR

$(this).siblings('video');

BTW, your HTML is incorrect, it should be:

<a class="play">Play</a> <!-- no need for '.' before the class attribute value -->

다른 팁

You can use .find:

$(this).parent().find("video");

Or .siblings:

$(this).siblings("video");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top