i am new to jQuery and i am having some rollover issues, i am trying to apply the same "roll over" effect to multiple divs, and it seems to work, the only thing is when i roll over an element all of my divs get the same effect, when i would like them to apply the effect one at a time on mouse over, here is my code
$('div.pitem').bind('mouseenter mouseleave', function() {
$('div.p-tab').toggleClass('pheader-bar-selected');
});
$('div.pitem').bind('mouseenter mouseleave', function() {
$('div.p-fline').toggleClass('pfooter-bar-selected');
});
I do realize that i have the same classes on all of my divs but i was hoping to find a way to do this with out giving every single div a unique class or id, any help would be amazing thank you!
What you are doing currently is on every hover you toggle the CSS class on all elements selected by
div.p-tab
, which will be any DIV with the CSS class p-tab.What you want to do is only toggle the CSS class on elements next to the hovered element in your HTML structure
div.pitem
.To find the currently hovered item, in your event use
this
keyword, and turn it into a jQuery object by using$(this)
. To find elements next to (adjacent) you will use thesiblings
function. You can also combine your two hover events.