English 中文(简体)
j 质量:独有的母体内的独有物体?
原标题:jQuery: Access unique object contained within unique parent?

假设如下:

<span class="container">
    <video class="video">
        <source ... />
    </video>
    <div class="controls">
        <div class="play">Play</div>
    </div>
</span>

使用 j I m 在文件负荷上加点功能,如:

$(document).ready(function() {

    $( .playpause ).click(function() {

        var play = $(this);
        var video =   ; // D:

    });

});

假定网页上或儿童母物体“控制”的视频数量没有限制。 我不想使用<代码>$(这一条)。

最佳回答

http://api.jquery.com/closest/"rel=“nofollow”>closestmeth 似乎好像在这里这样合适。

$(this).closest( .container ).find( .video );
问题回答
$(".video", $(this).parents(".container"))

应当工作。

您可使用prev()=获取先前的内容,这样,无论母集装箱内的视频和(或)控制内容的数量如何,都会这样做。

var video = $(this).parent().prev();

页 次

$(this) gets the "play" class div

http://www.un.org/Depts/DGACM/index_french.htm

<代码>prev(> 查阅了以前的内容(即对应的“个人”类别div)。

I d just add an data element with the videos reference on the link: Play Then

var video = $(this).data( ref );

与此类似:

var video = $( video , $(this).parentsUntil( span ,  .container ));




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签