13
rated 0 times
[
17]
[
4]
/ answers: 1 / hits: 26006
/ 12 Years ago, wed, december 26, 2012, 12:00:00
I'm creating a li item with a span inside. I've built an onclick function in the span to grab the parent li's ID to pass into a JSON get request. I'm unsure of how to create a unique ID and read it in the JS function. Since this is built dynamically I didn't build a switch but I feel like i'm missing another option.
The problem here is that I can't capture the Li ID. I've tried this and also tried based on class, but all seem to be failing.
Li object creation:
$(#jdLists).append('<li class=bigger id = ' + item.ID + '>'+
item.GROUP_NAME +
'<span title=Remove from list class= Sp icon icon-color icon-plus style=float: right; vertical-align: middle; '+
'onclick=spAdd()></span>' +
'</li>');
on click function:
function spAdd() {
$(this).closest(li).attr('id');
}
More From » jquery