Say I have:
<a href="http://foo.com" class="SiteClass">
Then I via jQuery I do some tests and conditionally update the class depending on the outcome, for example adding SiteDown
css via jQuery addClass
method, resulting in:
<a href="http://foo.com" class="SiteClass SiteDown">
I have the following JavaScript which does not fire:
$("a .SiteDown").on('click', function(e){
e.preventDefault();
e.stopPropagation();
alert('Clicked SiteDown');
});
What do I need to be able to fire an alert (or any other code there) when a link with class SiteDown
is clicked, keeping in mind this class can be added dynamically.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…