jeudi 28 février 2019

JavaScript "if X" then condition content replace

im trying to edit an shop content without editing HTML (code is closed for editions, i can add only some JS or CSS. There is a div:

<div class="product_section" id="projector_shipping_info" style=""><label>
Ready to send</label><div><span class="projector_delivery_days" 
id="projector_delivery_days" style="display: inline;">in 21 days   </span> 
</div><a class="shipping_info" href="#shipping_info" title="Check time and price"> Check time and price</a></div>

Im trying to make an "if" statement to replace hard "in 21 days" shipping time, into "in 3 to 10 days". I need to use IF, cause the shipping time is one of three possible status: 21 days, 9 days and 3 days. Would love to change it for "3 to 10 days", "2-4 days" and "1-2 days".

I've tested already (and it worked out)

document.getElementById('projector_delivery_days').innerHTML = '';
var p = document.createElement('p');
p.innerHTML = "Shipping in 3-5 days";
document.getElementById('projector_shipping_info').appendChild(p);

But its static one. Wish to make an IF from this. I've tried

document.body.onload=function(){ var
div1=document.getElementsById('projector_delivery_days')[0];  
if(div1.innerHTML=="in 21 days   "){
document.getElementsById('projector_delivery_days')[0].innerHTML="in 3 to 10 days   ";   }    }

But it appears to do nothing, same goes with

function shipping(){
var d1 = document.getElementById('projector_delivery_days');
  if(d1.innerHTML==='in 21 days   '){
  d1.innerHTML='in 3 to 10 days   ';
  document.getElementById('projector_shipping_info').appendChild(d1);
  }
};

I've been struggling with this for like 2-3 days. Can someone send some help?

Aucun commentaire:

Enregistrer un commentaire