Very simple method, that "toggles" the links:
$('ul li').each(function() {
if($(this).find('a').length > 0) {
$(this).text($(this).text());
}
else {
$(this).html($('<a />').attr('href', '#').text($(this).text()));
}
});
Example: http://jsfiddle.net/E2ryt/
Update:
From your comment I think you want this:
$('ul li').each(function() {
$(this).html($('<a />').attr('href', '#').text($(this).text()));
}).click(function() {
$(this).text($(this).text());
});
But I'm not 100% sure. See here: http://jsfiddle.net/E2ryt/1/
Update 2:
Based on David's comment, you might want this:
var lastClicked = null;
$('ul li').click(function() {
if(lastClicked) {
lastClicked.html($('<a />').attr('href', '#').text(lastClicked.text()));
}
lastClicked = $(this).text($(this).text());
});
See here: http://jsfiddle.net/E2ryt/2/