I have a button , when I click the button the it will create the link to my image. This is my code :
$("#btn").click(function () {
var $a = $('<a/>').attr('href', 'blahblah.com').addClass('contact');
$('#img1').wrap($a);
});
The problem : The link will create more and more while I click the button.
Question : How can I create only a link, although I click the button many times.
I hope you kindly to share idea. Thanks.
There is the .one() function in jQuery to enable the handler only for a one time action (see http://api.jquery.com/one/)