Fiddlevar $in = $('#input')
, $check = $('#check')
, $links = $('#links')
;
$check.on('click', function () {
var val = $in.val();
$in.val('');
$links.append(
"<a class='link' href='#'>%VALUE%</a>"
.replace('%VALUE%', val)
);
});
То же на чистом JavaScript без jQuery:
spoilervar els = {
input: document.getElementById('input'),
check: document.getElementById('check'),
links: document.getElementById('links'),
link: document.createElement('a')
};
els.link.className = 'link';
els.link.href = '#';
els.check.addEventListener('click', function(){
var a = els.link.cloneNode();
a.innerText = els.input.value;
els.input.value = '';
els.links.appendChild(a);
});
Fiddle