I have 2 arrays that have the exact same number of keys. I would like to loop through the first array, then search <p> tags for any matching values. Then if a match is found, I would like to replace that matching value with the corresponding value from the 2nd array.
I have this for now:
var text_original = ["original_word1", "original_word2", "original_word3"];
var text_replaced = ["replaced_word1","replaced_word2","replaced_word3"];
var z;
for (z = 0; z <= text_original.length; ++z) {
$("p").each(function(){
var text=jQuery(this).html();
$(this).html(text.replace(text_original,text_replaced));
});
}
This is the general idea, I'm getting confused how to isolate the single values from the multiple array values. Thanks in advance for help!
$("p")for ech iteration is a bad practice.