Jquery (this) help
Just wanted some quick help I'm 90% sure i need to use the (this) call/function because i need it to work on multiple objects on the page. but im 开发者_如何学运维not sure where or how to place it into my jquery code, im trying to create a hover state for a object once the user rolls over another , here is my jquery code, I hope this makes sense, thanks!
$("li.projectpost").hover(function () {
$("div.portfolio-title a").toggleClass("highlighter");
});
Basically all i really want to know is, I have more than one element on the page that I would like to apply a hover effect to, as is right now, when i hover over one item they all change, but I want to know is how to change the css in a child element when rolled over a parent I guess, I have a Div wrapper, that when hovered over an inside div changes, does that make better sense, Still trying to wrap my head around jquery thanks for the help! :)
Thanks for the help everyone! I just figured this out, I needed to use - jQuery(this).find(); thanks!
You can pass two callback functions to hover if you need that. I don't clearly get what you're doing there but I think this is what you need:
$("li.projectpost").hover(function () {
// This will call when mouse is over
}, function(){
// This will call when mouse is out
});
http://jsfiddle.net/tbq3x/13/
Just try the above fiddle. Your code works fine.
Thanks for the help everyone! I just figured this out, I needed to use -
jQuery(this).find(" ");
Inorder to select elements inside each other so my code ended up looking like this
$("li.projectpost").hover(function () {
// This will call when mouse is over
jQuery(this).find(".portfolio-title a").css("color","#00fcff");
}, function(){
// This will call when mouse is out
jQuery(this).find(".portfolio-title a").css("color","#ececec");
});
So far it seems to work great! thanks again!
$("li.projectpost").hover(function () {
$(this).toggleClass("highlighter");
});
The above should work, tell me how it goes.
Put your code in $(document).ready()
method
$(document).ready(function(){
$("li.projectpost").hover(function () {
$("div.portfolio-title a").toggleClass("highlighter");
});
});
精彩评论