Bryan Bryan - 1 year ago 93
jQuery Question

Access text-input attributes with jquery

I have the following code:

$('.centering').click(function (e) {
$(".thVal").replaceWith(function () {
return this.value;

This gives med the following output:

<input class="thVal" width="2" type="text" modelbind="LicenseHolder_LegalPerson_Name" value="Test Oil AB">
5505094091(rad 256)
<input class="thVal" width="2" type="text" modelbind="LicenseHolder_LegalPerson.PrimaryAddress_StreetAddress" value="Testgatan 1">
<input class="thVal" width="2" type="text" modelbind="LicenseHolder_LegalPerson_PrimaryAddress_ZipCode" value="50010">
5505094091(rad 256)
<input class="thVal" width="2" type="text" modelbind="x => x_LicenseHolder_LegalPerson_PrimaryAddress_HomeTown" value="Växjö Sverige">
5505094091(rad 256)
<input class="thVal" width="2" type="text" modelbind="" value="0730730037">

When I write
, the values of the inputs are displayed. But I want to access the value of the modelbind-attribute, and when I write
, I just get undefined.

How can I access the value?

Answer Source

You can get the value using .attr()


And it will be better if you use data-attribute