Patryk Imosa Patryk Imosa - 3 months ago 9
jQuery Question

JQuery not working in new tab

I work with JSF and spring boot. I have jquery script in my xhtml file that dynamically adds on click method to component that appears. Everything is working but when I copy link and open a new tab with this link. In new tab my JQuery script is run. On click is not working there. What do I wrong?

<script>
$('#menu\\:notification, #menu\\:notificationGrowlMessageError_container')
.on('click', showUserTaskListIfNotificationForUser);
</script>

Answer

You have to wrap it with $(document).ready(); like this:

<script>
    $(document).ready(function () {
        $('#menu\\:notification, #menu\\:notificationGrowlMessageError_container')
                .on('click', showUserTaskListIfNotificationForUser);
    });
</script>
Comments