Vote count:
0
By clicking Create I want to give continuing class name: For example now if you click Create button, it should create the following <div class="div_3">Div 3</div>:
<div id="container">
<div class="div_1">Div 1</div>
<div class="div_2">Div 2</div>
</div>
<input type="button" onclick="add()" value="Create"/>
Here is JS
function add(){
$("#container").append("<div>Div 3</div>")
}
asked 2 mins ago
1 Answer
Vote count:
0
One way is to count the existing elements (and add 1):
$("#container").append("<div>Div " + ($("#container div").length+1) + "</div>");
JSFIddle: http://ift.tt/1DOEPHR
answered 38 secs ago
On createing div element give ordered class name
Aucun commentaire:
Enregistrer un commentaire