I have this code and I want to show il in the elements which will be created by jquery , but il is undefined :
this is code :
<script>
$(document).ready(function(){
var il = 1 ;
$("#btn1").click(function(){
$("p").append(" <b>Appended text</b>.");
});
$("#btn2").click(function(){
$("ol").append("<li>Appended item " + il + " </li>");
var il = il + 1;
});
});
</script>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<ol>
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
</ol>
<button id="btn1">Append text</button>
<button id="btn2">Append list items</button>
this is output :
List item 1
List item 2
List item 3
Appended item undefined
Appended item undefined