if($(\'#term\').children().length == 0){
$(\"#term\").append(\"
\");
var i;
for(i=1;
Try with .trigger()
like
$('#'+liId).trigger('click');
do something like:
$("#term").append("<ul id='ulDynamic' class='ulDynamic'></ul>");
var i;
for(i=1;i<=3;i++){
var liDynamic = "Term "+i;
var liId = "Term"+i;
var $li = $("<li />", {
"id" : liId,
"class" : 'listDynamic'
}).html(liDynamic).click(function() {
alert("clicked:" + this.id);
});
$("#ulDynamic").append($li);
}
$("#ulDynamic").find("li:first").trigger("click");
Demo :: jsFiddle
I have seen your ID is starting with Term
so you can use .on() to add click event on DOM that are added later.
Exapmple
$(document).on('click','[id^="Term"]',function(){
//code here
});
use event delgation on
inside your ready function
try this
$(function(){
$('#term').on('click','li:first',function(){
//do your stuff
});
});