I'm new to jQuery and I'm just trying to mess around with it at the moment and learn the basics. Now, if I would like to use jQuery for a hover effect instead of CSS, how would I go about doing so (using functions other than .hover)?
Code
$(document).ready(function() {
$('li.menu a').mouseenter(function() {
$('li.menu a').css("background", "#006db0");
$('li.menu a').mouseleave(function() {
$('li.menu a').css("background", "#bbbbbb");
});
});
});
With the above code I have 4 links in a menu (li.menu a is the selector ofc). When I use the jQuery above, all 4 of them turn red when I hover over 1. I would like to know how to make it so only works on the current one I'm hovered over.
Unrelated to this problem, how long do you think I'd have to study jQuery before I can make a simple gallery by myself that lets me click the picture, open up a box on the page, and scroll through the rest? That's ultimately my goal. I would like to make a cool gallery for my portfolio as opposed to downloading a script.
EDIT: I know it's a lot easier to just do it in CSS but learning this way will help me get the syntax down at least lol. Surely I don't have to assign a class to each link in the menu and use that little bit of code for each one. That's the only way I know how to make it select just 1 instead of all 4.
Code
$(document).ready(function() {
$('li.menu a.gallery').mouseenter(function() {
$('li.menu a.gallery').css("background", "#006db0");
$('li.menu a.gallery').mouseleave(function() {
$('li.menu a.gallery').css("background", "#bbbbbb");
});
});
$('li.menu a.services').mouseenter(function() {
$('li.menu a.services').css("background", "#006db0");
$('li.menu a.services').mouseleave(function() {
$('li.menu a.services').css("background", "#bbbbbb");
});
});
$('li.menu a.resources').mouseenter(function() {
$('li.menu a.resources').css("background", "#006db0");
$('li.menu a.resources').mouseleave(function() {
$('li.menu a.resources').css("background", "#bbbbbb");
});
});
$('li.menu a.contact').mouseenter(function() {
$('li.menu a.contact').css("background", "#006db0");
$('li.menu a.contact').mouseleave(function() {
$('li.menu a.contact').css("background", "#bbbbbb");
});
});
});
That seems like way too much code for something simple.
This post was edited by Santora on Jun 9 2014 05:50pm