Reputation: 1089
How do change class of an element inside a div when the parent div is focused?
Like when I am active in the
<div id="window" class="fenster"><a class="bye"></a></div>
The class of A changes to hello?
Upvotes: 1
Views: 713
Reputation: 19
You can do this without jquery:
document.getElementById('window').setAttribute('class', 'newclassname');
Upvotes: 1
Reputation: 35793
Assuming by focused you mean mouse is over it and you can use jQuery?
$('#window').mouseover(function() {
$('a.bye', this).removeClass('bye').addClass('hello');
});
And if you want to reset the class when you move the mouse out:
$('#window').hover(function() {
$('a.bye, a.hello', this).toggleClass('bye').toggleClass('hello');
});
JSFiddle Example using only javascript
Upvotes: 2