English 中文(简体)
j 质量:如何对与其他要素共享名称的内容适用效力
原标题:jQuery: How to apply an effect to an element that shares a name with other elements

我正试图撰写一些法典,其中描述盒子在我掌握图像时散布。 我的网页上有多种图像。

<div class="image">
    <a href="?page=page1>"><img src="images/1.jpg" width="220" height="220"></a>
</div>
<div class="description" style="display: none;"> description 1 </div>

<div class="image">
    <a href="?page=page2>"><img src="images/2.jpg" width="220" height="220"></a>
</div>
<div class="description" style="display: none;"> description 2 </div>

<div class="image">
    <a href="?page=page3"><img src="images/3.jpg" width="220" height="220"></a>
</div>
<div class="description" style="display: none;"> description 3 </div>

我在“ j”或“ Java”中不很熟悉,但我提出这一守则,显示你在 image上的形象时所作的描述:

$(".image").hover(function() {
    $(".description").fadeToggle();
});

该法典的问题在于,如果你超越任何图像,那么所有描述都会蔓延。 我必须补充一下我的格鲁斯法典,这样,只有描述你所掌握的形象,才能战胜流行?

I have created a jsfiddle to help understand my problem: http://jsfiddle.net/qnWpy/ (also the description blinks erratically when I hover over or around the image, why s that?)

最佳回答
$(".image").hover(function() {
    $(this).next(".description").fadeToggle();
});

http://api.jquery.com/next/rel=“nofollow” http://api.jquery.com/next/

Updated your jsfiddle: http://jsfiddle.net/qnWpy/1/

FYI,$(这是目前选定的部分)。

问题回答

选择与被忽略的元素有关的描述。

$(".image").hover(function() {
    $(this).next(".description").fadeToggle();
});

这里需要的是“描述”,但可以防止ug。





相关问题
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.

热门标签