jquery - on click add a-tag with href from textarea -
i try since yesterday code work, cant. goal is: if click on button "a-tag" should wrapped around div , "href" a-tag should taken input-field user can paste in link f.e (somelink.html).
here got far: jsfiddle
$("#linkgo").click(function () { $("#wrapper").wrapinner("<a id='tablelink' href='#'></a>"); $('#link').change(function() { var newurl = $('#link').val(); $('a#tablelink').attr('href', newurl); }); }); i paste link in textarea, click on button , tag should wrapped around #wrapper href textarea. nothing happens.
i hope dont make stupid mistake , maybe there better way this.
try
$(document).ready(function() { $("#linkgo").one('click', function () { var = $("<a />", { id: 'tablelink', href: $('#link').val() }); $("#wrapper").wrapinner(a); }); $('#link').change(function() { var newurl = $('#link').val(); $('a#tablelink').attr('href', newurl); }); }); demo: fiddle
Comments
Post a Comment