```
var li = $("<li>").attr({
    id: "print",
    click: function(e){
     alert(this);
     console.log(this);
    }
 });

```

I have tried this code but it invokes sooner the code generates the HTML.