Refresh listview to add event handler to new added items
Description
The following code shows how to refresh listview to add event handler to new added items.
Example
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
src='http://code.jquery.com/jquery-1.8.3.js'></script>
<script type='text/javascript'
src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js"></script>
<link rel="stylesheet" type="text/css"
href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css">
<script type='text/javascript'>
$(window).load(function(){<!-- www . j a v a2 s. c o m-->
$('ul').on('click','li', function(){
alert('clicked');
});
$('ul').append('<li><a href="#">Cadillac</a></li>');
$('ul').listview('refresh');
});
</script>
</head>
<body>
<div data-role="page" id="p1">
<ul data-role="listview" data-theme="b">
<li><a href="#">Acura</a></li>
<li><a href="#">Audi</a></li>
<li><a href="#">BMW</a></li>
</ul>
</div>
</body>
</html>