javascript - jQuery "or" operator not working on mouseleave? -


$('.submenu' || '#categorymenu_100000') seems work on .submenu:

$(document).ready(function () {     $('li a').on("mouseenter", function () {         if ($(this).attr('href') == "/pages/men") {             $('#categorymenu_100000 .submenu').show();         }     });     $('.submenu' || '#categorymenu_100000').on("mouseleave", function () {         $('.submenu').hide();     }); 

'.submenu' || '#categorymenu_100000' javascript expression results in '.submenu', because '.submenu' truthy value – it’s string , isn’t empty. || picks first truthy value of operands.

if want select elements match either of selectors, you’ll need use css separator that: ,. jquery works on css selectors , not javascript expressions (it not magic).

$('.submenu, #categorymenu_100000').on('mouseleave', …); 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -