Hi I am trying to to replace already created list by new list dynamically using jquery. But on newly created list, I am not able to use any jquery event.
I have created a list of players
- Sachin
- Sourav
- Rahul
On clicking any list name it is alerting its id, then a newly created list is replacing dynamically using jquery.
- Kohli
- MS
- Rahane
But I am not able to pick the click event for newly created list. It is not showing any error in console and nothing happening when we click any name of new dynamic list.
<html>
<head>
<script src="jquery-3.1.1.js"></script>
<script>
$(document).ready(function(){
$("#videoul li").click(function(){
var vocab_id = $(this).attr('id');
alert("Hi the ID is " + vocab_id);
var aaila = '<a href="#" id="i_am_link">Click me again</a><ul id = "videoul"><li id="Kohli">Virat</li><li id="Dhoni">M S</li><li id="Rahane">Ajinkya</li></ul>';
$('#videowrapper').html(aaila);
});
});
</script>
</head>
<body>
<div id="videowrapper"><a href="#abc" id="i_am_link">Click me</a>
<ul id="videoul">
<li id="Tendulkar">Sachin</li>
<li id="Ganguly">Sourav</li>
<li id="Dravid">Rahul</li>
</ul>
</div>
</body>
</html>
I am clueless now, how to make this working.