开发者

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 + '\')" />');
  });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜