How do I detect a certain word in one span and apply it to another span using jQuery?

I have a dynamically generated code that resembles this:
<ul class="list-unstyled col-lg-12 no-padding">
	                         <li>
              <h2 class="priceUpdate"> da  €200.00</h2>
            </li>
			<span>
			<li>
				 <h2 class="priceUpdate"><i class="mfcustom-icon-twopay"></i>€193.00</h2>			  
			</li>
			</span>
            			
                      </ul>

Open in new window


I need to detect if in the h2.priceUpdate the string " da  " is present and if so insert it just after the <i class="mfcustom-icon-twopay"></i>

Could anyone help me work out how to achieve this via jQuery?

thanks
badwolfffAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

badwolfffAuthor Commented:
Ah! I forgot!

I also need to change that second h2 in an h5

thanks
Julian HansenCommented:
This should do it - working sample here
<script type="text/javascript">
$(function() {
  // GET THE H2 ELEMENTs
  var h2 = $('.priceUpdate');
  
  // MATCH da ON THE FIRST
  var m = h2[0].innerHTML.match(/(\s+da\s+)/g);
  
  // IF WE HAVE A MATCH THEN
  if (m) {
    // CREATE A TEXT NODE WITH THE da AND ADD AFTER THE <i>
    $('i.mfcustom-icon-twopay').after(document.createTextNode(m[0]));
    
    // CREATE THE H5 ELEMENT WITH THE HTML FROM THE H2
    var h5 = $('<h5/>').html(h2[1].innerHTML).addClass('priceUpdate');
    
    // ADD THE H5
    $(h2[1]).parent().append(h5);
    
    // AND REMOVE THE H2
    $(h2[1]).remove();
  }
});
</script>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
badwolfffAuthor Commented:
Thanks! I've learned a new trick or two here thanks to you!
Julian HansenCommented:
You are most welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.