Find and replace strings within tags with Jquery
<p>I am looking to create a tool that when it runs, it goes through a particular div on a page and finds all strings within set tags and then replaces these strings by going through an array and exchanging the letters in the string with its corresponding digit in another array.
Currently the below code does the required function but it seems to keep looping over the same tags and adding every updated string to previous tags.</p>

<p>Here is the code:</p>

<pre><code>  var arr = ['a','h1','h2','h3','h4','h5','h6','b','i','p','span','u'];
  var arr_alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
  var arr_update = ['0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26'];

  for(var i=0;i&lt;arr.length;i++)
  {
   $('.myDiv ' + arr[i]).each(function(index) 
   {
     var str = $(this).text();
     var arr_text = str.split('');

     for(var j=0;j&lt;arr_text.length;j++)
     {
        var change = $.inArray(arr_text[j],arr_alphabet);
        if(change &gt;-1)
        {
           arr_text[j] = arr_update[change];
        }
     }

     var result = arr_text.toString();
     var result_final = result.replace(/\,/g,'');
     $('.myDiv ' + arr[i]).append(' ' + arr[i] + ' ' + arr_text[i] + ' [tag]');
  });
</code></pre>

<p>Is there a way to update each tag and move onto the next one without continually updating the previous tags.</p>

<p>Thanks.</p>
