I’m in the process of learning JQuery, and I’m looking to have a list of links that trigger another Javascript function when clicked. The code I have right now (below) makes the <li> tags successfully, but the inner JQuery is returning an object (“1. [object Object]”) instead of the text with a link tag wrapped around it.
$('<li></li>', {
text: $('<a></a>', {
text: data[i].name,
onclick: 'doSomething()'
}),
id: 'response'
}).appendTo('ol.responseList');
Your help’s greatly appreciated!
Use
htmlinstead oftext.P.S. I suggest not using
onclickattributes to bind events. Use jQuery’s event API.UPDATE: If you want to pass
itodoSomething, you need to do something like this (outside of the loop):And then do this: