admin管理员组文章数量:1296843
I have an input box created by jquery like so:
val input = $('<input class="pick_date" ... />')
but the .html() method on input does not return the string entered inside the $. does anyone know why?
edit: Ah, I understand the problem. Is there a way to get the html representation of the entire input box and not just the entry?
I have an input box created by jquery like so:
val input = $('<input class="pick_date" ... />')
but the .html() method on input does not return the string entered inside the $. does anyone know why?
edit: Ah, I understand the problem. Is there a way to get the html representation of the entire input box and not just the entry?
Share edited Sep 8, 2009 at 22:00 Nathaniel Flath asked Sep 8, 2009 at 21:53 Nathaniel FlathNathaniel Flath 16k19 gold badges73 silver badges94 bronze badges 03 Answers
Reset to default 5you are passing <input />
which is a self-closing tag.
If you were passing <input>Html here</input>
(which is valid XML but not HTML to my knowledge), you could retrieve the "Html here" part with the .html() function like so:
var input = $('<input class="pick_date">Html here</input>');
alert(input.html());
In addition to your edited question:
$('<input />').outerHtml();
this should work.. :)
with this ofcourse (source):
(function($) {
$.fn.outerHTML = function() {
return $('<div>').append( this.eq(0).clone()).html();
};
})(jQuery)
I think maybe you are looking for append():
$("div#form").append('<input class="pick_date" ... />');
Just had to deal with this problem.
If you are using ASP.NET, it could be because ASP.NET changes the id names, if you add "runat="server".
So instead of doing this:
<td id="mytd" runat="server"></td>
$('#mytd').html()
Try doing this:
<td id="mytd" class="myclass" runat="server"></td>
$('.myclass').html()
本文标签: javascriptjquery html() not workingStack Overflow
版权声明:本文标题:javascript - jquery html() not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741646169a2390195.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论