I have some links on my site for which I am trying to trigger a click event handler. In HTML, the content where the links occur is like so:
<div class = "panel-container messages">
<div class="ld-course-navigation">
<ul class="ld-table-list notificationsList">
<li class="notification-item">
<a href="somelink?read=id" class="grid gs8 gsx">
<div class="fa Webinar site-icon grid--cell"></div>
<div class="item-content grid--cell fl1">
<div class="item-header">
<span class="item-type ">Webinar</span>
<span class="item-creation">
<span title="title" class="relativetime">3 hours ago</span>
</span>
</div>
<div class="item-location">A live webinar has started</div>
</div>
</a>
</li>
</ul>
</div>
</div>
The code I was using was
$(".notification-item a").click(function (e) {
e.preventDefault();
console.log('clicked notification');
// do some stuff, first seeing if the url has the read url param
});
I really just need to run this handler when the url clicked is one containing the url param read
but wasn't sure how to do that so just decided to tend to that checking inside the handler.
With above, I noticed the handler was not triggering. Then I noticed that in one of my site's plugins (it is a Wordpress site), there was this click function:
$('body').on('click', '.ld-course-navigation a', function(e) {
if ($(window).width() < 900) {
e.preventDefault();
console.log('clicked link on narrow screen to ' + $(this).attr('href'));
closeFocusSidebar();
window.location.href = $(this).attr('href');
}
});
where .ld-course-navigation a
of course is also selecting the links of the sort I show above, and the console output showed it was being called.
So I got to thinking this must be some sort of case where only one of these click functions is being allowed to run.
Now I read this question and I understand that multiple click functions should indeed be able to run, but only one will run if you are using inline onclick
.
As far as I can tell, my implementation does not amount to inline
usage (or does it?), so not sure how to ensure that my click handler works.
What can I try next? Ideally it would amount to not touching the plugin's JavaScript and just editing my own.