add text-box on click of link
I need to add a text-box (within a container) on click of link. Text-box will have value equal to 'href' of a link
My jQuery code is like:
jQuery("a.link").click(function(event){
jQuery('#link-container-text').text('<input type="text" onclick="this.select();" value="' + this.href + '" />');
});
But instead of showing the text-box, it's showing me HTML code.
开发者_Go百科I need text-box, not HTML code.
EDITED
On click of another link, How can I remove just-added input from #link-container-text.
use .append or .html()
jQuery('#link-container-text').append('<input type="text" onclick="this.select();" value="(\'' + this.href + '\')" />');
.text is for value
removal of the added element
$("#link-container-text").find("input").remove();
Replace .text with .html. Note that this will replace the entire html of that element
jQuery("a.link").click(function(event){
jQuery('#link-container-text').html('<input type="text" onclick="this.select();" value="(\'' + this.href + '\')" />');
});
精彩评论