If you are trying to extract the value from all the <p>, <h1>, <h2>
and <h3>
elements then your code should look like this. I am using the <h3>
as an example.
jQuery(document).ready(function(){
var tel4 = $("h3");
})
Here we are using jQuery to target all the <h3>
elements and store the reference to those <h3>
elements in the variable var tel4
. It is a good practice to name such variables with a $
before the name, like so $tel4
.
We can then use the jQuery .each()
function to loop over all the <h3>
elements that were stored in our tel4
variable and see if any of them contain the number 855-322-8671
.
$.each(tel4, function() {
var number = "855-322-8671";
var replacement = "1-855-Factor-1"
if ($(this).is(':contains("' + number + '")')) {
$(this).html(function() {
return $(this).html().replace(number, replacement);
})
}
})
The above code will search every <h3>
that contains the number
and replace that number with our replacement
.
Hope this helps!