admin管理员组文章数量:1400469
I have div with a few links spread out in the content. I would like to highlight all the links in the div onmouseover. Is there jquery solution that works in FF, IE and chrome.
Thanks.
I have div with a few links spread out in the content. I would like to highlight all the links in the div onmouseover. Is there jquery solution that works in FF, IE and chrome.
Thanks.
Share Improve this question asked Sep 24, 2010 at 16:53 NickNick 3854 gold badges8 silver badges16 bronze badges6 Answers
Reset to default 4How about no JavaScript?
Style.CSS
.linkdiv a {
color: blue;
}
.linkdiv:hover a {
color: red;
}
I wanted to test this, but sadly jsfiddle isn't iPhone patible :(
Demo
HTML:
<div id='links'>
This is simple text<br />
<a href='#'>Link1<a/><br />
<a href='#'>Link2<a/><br />
<a href='#'>Link3<a/><br />
</div>
jQuery:
$('#links').live('mouseover', function(){
$('#links > a').addClass('highlight');
});
$('#links').live('mouseout', function(){
$('#links > a').removeClass('highlight');
});
CSS:
.highlight {
background-color : red;
}
You can edit CSS part to highlight in your favorite style.
The Best Solution, As far as my concern =)
Markup :
<h1>CSS is cool! </h1>
<ul id="css">
<li><a class="links" href="#"> Link1 </a></li>
<li><a class="links" href="#"> Link2 </a></li>
<li><a class="links" href="#"> Link3 </a></li>
<li><a class="links" href="#"> Link4 </a></li>
</ul>
CSS :
#css li { margin:0px 5px;list-style:none; float:left;}
#css .links { color :#0099f9; text-decoration:none;font:bold 20px Arial;}
#css:hover a.links { color : #f0f;}
something like this (in your document ready) should do it!
$('#MyDiv').live('mouseenter', function(){
$(this).find('a').addClass('highlight');
});
$('#MyDiv').live('mouseleave', function(){
$(this).find('a').removeClass('highlight');
});
Give all the links the same class and then do this:
$(document).ready(function() {
$('.someClass').hover(function() {
$('.someClass').css('underline' : 'solid 1px #FFF');
});
})
If I remember correctly, you should be able to just do:
$('div selector').hover(function(e) {
$(this).find('a').doThings();
},
function(e) {
$(this).find('a').undoThings();
});
I'd also suggest switching the explicit $.hover()
call (just provided as an example) to use $.delegate()
or $.live()
.
本文标签: javascriptHow to highlight links in the div on mouseoverStack Overflow
版权声明:本文标题:javascript - How to highlight links in the div on mouseover - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744236352a2596573.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论