I have to clear/remove notification based on user scrolling means clear the notification if user has seen it. It's a pop-up window for notification. The seen notification should be cleared/removed only after user close the pop-up notification window. I am new to Javascript/jQuery, so confused how to do it. Here is my code.
<div class="notifications" id="notifications">
<p class="notif" id="1"> First notification <span id='time1'></span></p>
<p class="notif" id="2"> Second notification <span id='time2'></span></p>
<p class="notif" id="3"> Third notification <span id='time3'></span></p>
<p class="notif" id="4"> Fourth notification <span id='time4'></span></p>
<p class="notif" id="5"> Fifth notification <span id='time5'></span></p>
<p class="notif" id="6"> Sixth notification <span id='time6'></span></p>
</div>
<script>
jQuery(function($) {
$('#notifications').on("scroll", function() {
$('.notif').each(function () {
if( $(this).next().offset() ) {
console.log("current: " + $(this).offset().top);
console.log("next: " + $(this).next().offset().top);
if( $(this).offset().top <= $(this).next().offset().top ) {
$(this).find( ".notif" ).css( "color", "red" );
//return;
}
}
});
});
});
</script>
In console log, it displays current and next pos value and then it displays error: TypeError: $(...).next(...).offset(...) is undefined
I am also confuse how to clear/remove the seen notification after user close the pop-up notification window.