I don't even want to know how if the code you posted does even work.
var notWhatYouWanted = false;
var $t = $(this);
var $ci = $('#chosedItem');
var idString = 'whatever';
if (notWhatYouWanted) {
idString = $('#selector').attr('whatever');
}
var $li = $('<ul><li /></ul>').attr('id',idString).text($t.children(0).text());
$ci.append($li);