javascript - Applying a CSS style to a class based on another class on the same level - Stack Overflow

I have a jquery carousel that is applying a class of 'active' to an image that is in a div.

I have a jquery carousel that is applying a class of 'active' to an image that is in a div. In this same div I also have a span with a class of 'fade' which is applying a css style of opacity: 0; I am wondering if there is a way either with CSS or javascript to change the CSS style of span class to opacity: 1; when the image (which is on the same level of the span tag) has the 'active' class applied to it.

<div> 
     <img src="image1" class="active">
     <span class="fade">
         <p>Text</p>
     </span>
</div>

I have a jquery carousel that is applying a class of 'active' to an image that is in a div. In this same div I also have a span with a class of 'fade' which is applying a css style of opacity: 0; I am wondering if there is a way either with CSS or javascript to change the CSS style of span class to opacity: 1; when the image (which is on the same level of the span tag) has the 'active' class applied to it.

<div> 
     <img src="image1" class="active">
     <span class="fade">
         <p>Text</p>
     </span>
</div>
Share Improve this question asked Dec 30, 2012 at 8:21 Tristan MartinTristan Martin 351 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

In CSS use adjacent sibling selector:

img.active + span.fade {
    /* styles here */
}​

DEMO: http://jsfiddle/QBfPg/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745451871a4628308.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信