jquery - dynamically change the name attribute of an element -
i have jquery function takes following html page using this:
//get html var myhtml = $("#info").html()
here's html gets:
<div id="info"> <table> <tr> <td><input type="text" name="tbanswer" value="feedback..." /></td> </tr> </table> </div>
i'm trying change name of textbox name attribute follow counter. name="tbanswer1"
i tried this:
$(document).on('ready', function () { $("info").closest("input").attr("name", "tbanswer" + mycounter); });
but it's not finding it.
is there way of doing jquery?
thanks!
you forgot #
:
$("#info").find("input").attr("name", "tbanswer" + mycounter);
and want find
, not closest
. find
gets descendants, input
is.
Comments
Post a Comment