I have code similar to this:
<div>
<div> randomText 11235 </div>
<div> randomText </div>
<div> randomText </div>
<div> randomText </div>
<div> randomText </div>
</div>
As you can see, each div contains random text but the first div also has a “11235” added at the end.
This “11235” will be added at the end of any of the divs (Note that this can be multiple divs).
Here is one scenario that can happen:
<div>
<div> randomText </div>
<div> randomText 11235 </div>
<div> randomText </div>
<div> randomText 11235 </div>
<div> randomText </div>
</div>
Is is possible to be able to target those divs that only have the 11235 added onto the end and remove the 11235.
I would prefer a solution in javascript (jQuery is fine).
Thanks
Using jQuery you could iterate all divs containing 11235 and replace ‘11235’ in the text of those elements using the standard js-replace function:
As noted by Rick you could also use implicit iteration, it’s slightly more elegant:
If there’s any chance each div element might contain multiple occurances of 11235 use the regex-version of replace: