Mark
Mark

Reputation: 11359

How to set :hover on a li(A) when hover an other li(B)

I am daily an iOS developer, but i'm trying to give a help for a friend in php and jquery, since I didn't do Jquery for a lonnng time, im asking you guys a little help :)

So let's say I got this, for a unique ID

< li class="listname" value="'.$id.'">

When I go hover this, I want to li:hover this for the same unique ID

< li class="listpicture" value="'.$id.'>

My CSS job is done, when I go hover one, it does the job.

I began my script with something like that

$("li.listname").mouseover( function() {
  var id = $("li.listpicture").attr('value');

// and miss some job here
}

I feel a little bit noob on this, but I will feel free to help you with iOS Developement :)

Thx

Upvotes: 1

Views: 347

Answers (1)

Loktar
Loktar

Reputation: 35309

Could make a new class for the hover effect and just assign it and remove it on hover. Im making the assumption that id is the id of the other element you want to show the hover effect on.

css

li:hover, .active {/*styles*/}

JS

$("li.listname").hover( function() {
  var id = $("li.listpicture").attr('value');
  $(id).addClass('active');
},function(){
    var id = $("li.listpicture").attr('value');
    $(id).removeClass('active');
});

Live Demo

Upvotes: 2

Related Questions