I have an id #navigation li a and a class .menu-description . I want to change class from .menu-description to .menu-descriptionnew whenever user hovers on #navigation li a
My jquery so far:
<script>
$(document).ready(function() {
$('#navigation li a').onmouseover(function() {
//Check if element with class exists, if so change it to new
if ($('div.menu-description').length != 0)
$('div.menu-description').removeClass('menu-description').addClass('menu-descriptionnew');
//Check if element with class 'menu-descriptionnew' exists, if so change it to 'menu-description'
else if ($('div.menu-descriptionnew').length != 0)
$('div.menu-descriptionnew').removeClass('menu-descriptionnew').addClass('menu-description');
});
});
</script>
But it's not working. Any suggestions? Thanks!
The jQuery event is " mouseover " not "onmouseover"
You could clean up your code a lot with the use of and the 和清理代码
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.