if (selectedCountry == "USA") {
$("#state").show();
}
How can I change name for my div #state with the same condition?
(to add name="NewName"
to my div id="state"
)
Smth like:
i开发者_如何学编程f (selectedCountry == "USA") {
$("#state").show();
$("#state").name("NewName"); <-- ?
}
Use .attr()
to set attributes on an element, for this:
if (selectedCountry == "USA") {
$("#state").show().attr("name", "NewName");
}
If setting many at once, you can also pass an object, for example:
if (selectedCountry == "USA") {
$("#state").show().attr({ name: "NewName" });
}
I'm assuming you meant a <select>
here with a dropdown, since a <div>
won't be serialized into a form a name
attribute isn't useful or valid, if this isn't the select, just find the form element and perform the same .attr()
call.
if (selectedCountry == "USA") {
$("#state").show();
$("#state").attr("name","NewName");
}
精彩评论