0

If I have some JQuery object $("#someDiv"), for which its html(),

$("#someDiv").html(); 

equals something like:

<div id="bla_i">
  <input ... id="ble_i" />
</div>

(That is: a lot of nested elements, some of them having id's and names containing " _i ")

How can I make all those "_i" to be "_5" ? How can I replace all the "_i" in some JQuery Object?

1 Answer 1

1
var html = $('#someDiv').html();  // get the html string

$(html)  // make jQuery object
       .find('[id*="_i"]')  // find elements with id contains "_i"
       .attr('id',function(i, oldId) {
          return oldId.replace('_i', '_5');  // replace all "_i" with "_5"
       });
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.