# Other Languages > jQuery >  [RESOLVED] how to click the appended li ?

## DeadlyMan

hi 
i want to click the appended <li>

i append a <li> into <ul>

and now i want to click them but it's don't work fine

here is my append code JQ :


```
$('li').append($('<p>').text(post.w_name).attr('name','post_'+post.w_id).attr('id','post_'+post.w_id).addClass('f_ok'));
```

and here my html code :



```
<ul dir="rtl">
    <li><h1>Online</h1></li>
</ul>
```


i want to do this :


```
            $('li p').click(function(){
                alert($(this).text())
            });
```

it's don't work with me  :Frown:  help 

and thanks

----------


## SambaNeko

When you assign a callback function using .click(function(){}), it can only be assigned to currently-existing DOM elements.  If your append() is occurring after the assignment, it won't work that way.

There are at least two ways of dealing with this.  One is to use the .on() function, which can assign callbacks for elements that will exist in the future.  The other approach is to specifically attach the callback to your <p> element when you're creating it:


```
var newPara = $('<p></p>');
newPara.text(post.w_name)
	.attr('name','post_'+post.w_id)
	.attr('id','post_'+post.w_id)
	.addClass('f_ok')
	.click(function(){
		alert($(this).text())
	});
$('li').append(newPara);
```

This is a good approach if you want the callback to be assigned specifically to just that element.

----------


## DeadlyMan

thanks for helping me  :Wink:

----------

