I'm trying to utilize a selector on .mouseenter that was just added to an element with a click function in the same script. But it doesn't recognize the selector. The selector has to be there initially in the HTML for it to work.
HTML
<div class="nav-block">
<div class="nav-item closed">
<div class="detail">Resources</div></div></div>
jQuery
$('.detail').click( function() {
$('.nav-item').addClass('open').removeClass('closed');
});
$('.nav-item.open').mouseenter(
function(){
$('.nav-item').removeClass('open').addClass('closed');
});
The mouseenter only seems to work if I set the .open class to the .nav-item in the initial HTML. But not after it gets added by the jQuery.
Actually I'm trying to close the open one when I rollover the closed ones, but I reversed it for simplification for this question. Basically it comes down to recognizing the selector I just added, and it still utilizes the selector that was just replaced. If I change the selector for mouseenter to the .closed, then it closes itself even though that .closed class was just replaced.
Hope this make sense. Thanks for any help or guidance you can provide.
Here is a JSFiddle