here is my scenario I have a nested sortable tree simplified looks like this
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title></title>
</head>
<body>
<ul>
<li id="item_123" name="123">
<fieldset class="additem">
<input type="text" name="title" value="">
</fieldset>
<ul>
<li id="item_253" name="253">
<fieldset class="remove additem">
<input type="text" name="title" value="">
</fieldset>
</li>
<li id="item_252" name="252">
<fieldset class="remove additem">
<input type="text" name="title" value="">
</fieldset>
</li>
<li id="item_250" name="250">
<fieldset class="remove additem">
<input type="text" name="title" value="">
</fieldset>
</li>
<li id="item_247" name="247">
<fieldset class="remove additem">
<input type="text" name="title" value="">
</fieldset>
</li>
</ul>
</li>
</ul>
</body>
</html>
now where the fieldset has an additem class I want to add new items to the tree that will look like all the other items in the tree and I can do that no problem
all i do is add alittle jquery that adds a button and attach a click event to it.
and I have most of my code here
$(document).ready(function(){
$('<p class="add">Add <img src="/add.png" alt="up.png" /></p>').click(function() {
add_item(this);
}).prependTo("fieldset.additem");
}
function add_item(btn){
var li ='
<li id="item_new'+ X+'" name="new"'+ X+'>'+
'<fieldset class="remove additem">'+
'<input type="text" name="title" value="">'+
'</fieldset>'+
'</li>';
if(!$(btn).parent().next('ul').length) {
$(btn).parents("li:first").append("<ul>"+li+"</ul>");
}else {
$(btn).parent().next("ul").prepend(li);
}
}
notice in the above code i call a variable X that needs to be a number so that the new Items can be unique so that is what I'm looking for how to keep track of all the new items I put in to my tree
any help would be appreciated
EDIT I mentioned that I using an x variable seems sloppy but I would also like to mod this function down the road so that I can us it to add all kinds different items so I ues new+ x or old + x