For example if have:
<div>New York</div>
So I would like to print another div like this:
<div>Free Delivery</div>
How would I do that using JS?
CodePudding user response:
add id to element :
<div id="country">New York</div>
and then
let country = $('#country')
setInterval(()=>{
if(country.text()=='New York'){
// Your code
// exemple
alert('Congratulations ! We Ship for Free for New York
Customers');
}
},3000)
i hope it was useful
CodePudding user response:
you can do this with simple js condtion:
add a class/id to to the element <div id="country">New York</div>
and in your script:
const country = document.querySelector('#country');
const printdiv = '<div>Free Delivery</div>';
if(country && country.textContent.trim() == 'New York'){
document.querySelector('#country').insertAdjacentHTML('afterend',printdiv)
}