I have a website consisting a few href links and 2 buttons that can change what those links are.
<div class="links">
<p class="hlCategory">Classical Mechanics</p>
<ul>
<li><a class="topic_link" href="#">Position, Velocity, Acceleration</a></li>
<li><a class="topic_link" href="#">Newton's Laws</a></li>
<li><a class="topic_link" href=“#">Friction</a></li>
</ul>
</div>
<div class="buttons">
<p>Choose Dificulty:
<button type=“button" onclick=“beginerButtonAction(this)">Beginer</button>
<button type=“button" onclick="intermediateButtonAction(this)">Intermediate</button>
</p>
</div>
After the original html is loaded, when links are clicked, the alert function in the javascript file is triggered.
$(function(){
$(".topic_link").click(function(){
alert($(this).text());
});
});
And everything works fine.
The problem arises after the buttons are pressed and the href are changed.
function beginerButtonAction(id) {
$( "div.links" ).remove();
var newLinks;
newLinks= '<div class="links">'+
'<p class="hlCategory">Classical Mechanics</p>'+
'<ul>'+
'<li><a class="topic_link" href=“#”>Moment of Inertia</a></li>'+
'</ul>'+
'<p class="hlCategory"></p>'+
'<ul>'+
'<li><a class="topic_link" href=“#">Drag Force</a></li>'+
'</ul>'+
'</div>';
var $jNewLinks = $(newLinks);
$("body").append($jNewLinks);
}
function intermediateButtonAction(id) {
$( "div.links" ).remove();
var newLinks;
newLinks= '<div class="links">'+
'<p class="hlCategory">Classical Mechanics</p>'+
'<ul>'+
'<li><a class="topic_link" href=“#”>Torque</a></li>'+
'</ul>'+
'<p class="hlCategory"></p>'+
'<ul>'+
'<li><a class="topic_link" href=“#">Momentum</a></li>'+
'</ul>'+
'</div>';
var $jNewLinks = $(newLinks);
$("body").append($jNewLinks);
}
After the html is modified the href no longer triggers the alert. I want the alert to fire after html is changed. Any thoughts?