') but the .h...">

Jquery html () not working

I have an input field created by jquery like:

val input = $('<input class="pick_date" ... />')

      

but the .html () method on input does not return the string entered inside $. does anyone know why?

edit: Ah, I understand the problem. Is there a way to get the html representation of the entire input field, not just the record?

+2


source to share


3 answers


you're passing <input />

which is a self-closing tag.

If you passed in <input>Html here</input>

(which is valid XML, but not HTML as far as I know), you can get the Html part here 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 path ( source ):

(function($) {
    $.fn.outerHTML = function() {
        return $('<div>').append( this.eq(0).clone()).html();
    };
})(jQuery)

      

+4


source


I think maybe you are looking for append ():



$("div#form").append('<input class="pick_date" ... />');

      

0


source


I just had to solve this problem.

If you are using ASP.NET, it might be because ASP.NET changes the names of the names if you add "runat =" server ".

So instead of this:

<td id="mytd" runat="server"></td>
$('#mytd').html()

      

Try this:

<td id="mytd" class="myclass" runat="server"></td>
$('.myclass').html()

      

0


source







All Articles