Created
February 7, 2012 13:08
-
-
Save mbjordan/1759598 to your computer and use it in GitHub Desktop.
Simple jQuery function that changes an <a> element to an <input> for copying the href contents.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// USE: <a href="http://yoursite.com/" rel="copylink">yoursite.com</a> | |
$(document).ready(function () { | |
$(window).on("click", "a[rel=copylink]", function (e) { | |
e.preventDefault(); | |
var href = $(this).prop("href"), | |
txt = $(this).text(); | |
$(this).hide().parent().html('<input type="text" value="' + href + '" data-href="' + href + '" data-txt="' + txt + '" width="20" class="copyinput">'); | |
$(".copyinput").focus().select() | |
}).on("blur", ".copyinput", function () { | |
var href = $(this).data('href'), | |
txt = $(this).data('txt'); | |
$(this).hide().parent().html('<a href="' + href + '" rel="copylink">' + txt + "</a>") | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment