Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Onmouseover change CSS class from other element

Tags:

javascript

I'm trying to make an JS, but since I'm not an expert on that, maybe someone could help me. I was searching for that in Google and in Stack Overflow, but didn't find what I need. I just found onmouseover that change the class in element itself. But I want something different:

I want to make a onmouseover on a tag to change the class closed to open in other element. Example:

<a href="#" onmouseover="<active event>">Link</a>

<ul class="dropdown closed"><li>Item</li></ul>

Regards,

like image 476
euDennis Avatar asked Apr 08 '13 19:04

euDennis


2 Answers

You can use <a href="#" onmouseover="changeClass">Link</a>

And JS:

function changeClass() {
    document.getElementById("other-element").className = "open";
}

More advanced JSFiddle: http://jsfiddle.net/eRdHJ/1/

like image 67
Alfred Xing Avatar answered Sep 18 '22 18:09

Alfred Xing


If you include jQuery:

Add id for your elements:

<a href="#" id="a1">Link</a>
<ul class="dropdown closed" id="ul1"><li>Item</li></ul>

Javascript:

$("#a1").mouseover(function(){
  $("#ul1").addClass("open").removeClass("closed")
})
like image 23
Mihail Avatar answered Sep 21 '22 18:09

Mihail