I have a basic html and a javascript function as below. When I serialize the form by form Id, it works. But I want to serialize a piece of html content that doesnt a form such as $('.FormReference').serialize().
What can’t I do this?
$(function () {
$('#btnLogin').click(function (event) {
alert($('#form1').serialize());
});
});
<form id="form1" runat="server" action="">
<div>
<table class="FormReference">
<tr>
<td>
<input type="text" id="_Username" name="Username" />
</td>
<td>
<input type="text" id="_Password" name="Password" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" id="btnLogin" value="Login" />
</td>
</tr>
</table>
</div>
</form>
From the documentation:
So you have two options: