I have a series of repeated divs with content being injected via jQuery. By the way, the number of parent divs is dynamic, and can therefore be random.
Within each div, I have anchors (H3 a) that trigger a modal window. My problem is, each time the target element is clicked, each section being injected into the parent div triggers the modal window.
So, my question is, how do I isolate each parent so only the current one triggers the modal, without having to excessively use .eq()?
Here's a snippet of my script that triggers the modal window:
//prepend modal window to positive message container
jQuery('.rateRibbon').each(function () {
jQuery(this).append('<div class="modelessWindow hideWindow">' + modWin1 + '</div>');
});
//remove class to show modeless window
jQuery('.posMsg a.showWindow').click(function (e) {
jQuery('.modelessWindow.hideWindow').removeClass('hideWindow');
});
//add class to hide modeless window
jQuery('.modelessWindow a.closeModWin').click(function (e) {
jQuery('.modelessWindow').addClass('hideWindow');
});
//when .roomTypeLineItem is clicked add class to hide nested modal window
jQuery('.roomTypeLineItem').click(function (e) {
jQuery('.modelessWindow').addClass('hideWindow');
});
And a link to my Fiddle with the entire script.
Thanks in advance for your help!