获取点击元素jQuery的HTML内容 [英] get the HTML content of clicked element jQuery
问题描述
我有以下HTML
< label class =editableid =user_info_username>海世界。 ..< /标签>
现在点击功能我需要点击元素的内容。
我试过了
$ b $ $ p $ $ $ $ $ $。editable)。live(click,function() {
alert($(this).html())//返回海世界...
});
但我需要HTML内容
所以< label class =editableid =user_info_username>海洋世界...< / label>
var html = $('< div />')。append($(this).clone ())的HTML();
我之前也写过一个插件,它在 https://stackoverflow.com/a/6509421/6782
< code(function($){
$ .fn.outerhtml = function(){
return $('< div />')。append(this.clone()) .html();
};
})(jQuery);
I have the following HTML
<label class="editable" id="user_info_username">Hai world...</label>
now on click function i need the content of the clicked element .
i tried
$(".editable").live("click",function(){
alert($(this).html()) //returns Hai world...
});
But i need the HTML content
so <label class="editable" id="user_info_username">Hai world...</label>
Clone the clicked element, wrap it in a <div>
, and then ask for the HTML of that - something like:
var html = $('<div/>').append($(this).clone()).html();
Working demo at http://jsfiddle.net/f88kj/
I also previously wrote a plugin that does this at https://stackoverflow.com/a/6509421/6782
(function($) {
$.fn.outerhtml = function() {
return $('<div/>').append(this.clone()).html();
};
})(jQuery);
这篇关于获取点击元素jQuery的HTML内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!