javascript - manipulating dynamically created form elements without losing their values with jQuery -
i want search , replace on complex bit of dynamically created form. it's simple finding instances of 1 string , replacing them another, made more complicated fact there 11 instances per bit of form , make parts of various attributes.
examples of kind of thing i'm working (it's '001' bit i'm searching , replacing):
<div id="step_title:001|title"> <label for="step_title:001|title|field"> <input id="step_title:001|title|field" name="step_title:001|title|field"/>
i had thought trick:
$(this).html($(this).html().replace('old string', 'new string'));
however because bit of form dynamically added form data lost every time perform action. tried using .clone() function seems preserve data, doesn't allow manipulate object. tried performing search , replace directly onto containing object, guess .replace() works on strings.
can update attributes instead?
$('div, label, input').each( function() { var _this = $(this); _this.attr('id', _this.attr('id').replace('old string', 'new string')); _this.attr('for', _this.attr('id').replace('old string', 'new string')); _this.attr('name', _this.attr('id').replace('old string', 'new string')); } );
might bit longwinded...
Comments
Post a Comment