0

My custom code conflicts with some other JavaScript file in my WordPress website.

Code which ocurs conflict is here. When I remove google APIs for jQuery everything works fine except this code then it stops working. I have tried to modify code with noconflict but it did not help. Maybe I did it wrong.

Website

When script is there it makes address delivery checker stop working.

<script>$.noConflict();</script><script 
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="pondelok" class="msg">
<h4>Objednávky dnes prijímame od 11:00 do 21:00.</h4>
</div>
<div id="utorok" class="msg">
<h4>Objednávky dnes prijímame od 11:00 do 21:00.</h4>
</div>
<div id="streda" class="msg">
<h4>Objednávky dnes prijímame od 11:00 do 21:00.</h4>
</div>
<div id="stvrtok" class="msg">
<h4>Objednávky dnes prijímame od 11:00 do 21:00.</h4>
</div>
<div id="piatok" class="msg">
<h4>Objednávky dnes prijímame od 11:00 do 21:00.</h4>
</div>
<div id="sobota" class="msg">
<h4>Objednávky dnes prijímame od 11:00 do 21:00.</h4>
</div>
<div id="nedela" class="msg">
<h4>Objednávky dnes prijímame od 11:00 do 20:00.</h4>
</div>

<script>
var Now = new Date();
var CurrentDay = Now.getDay();
var CurrentHrs = Now.getHours();
if (CurrentDay == 1 && (CurrentHrs >= 00 && CurrentHrs <= 24)) {
$('.msg').hide()
$('#pondelok').show();
}else if (CurrentDay == 2 && (CurrentHrs >= 00 && CurrentHrs <= 24)) {
$('.msg').hide()
$('#utorok').show();
} else if (CurrentDay == 3 && (CurrentHrs >= 00 && CurrentHrs <= 24)) {
$('.msg').hide()
$('#streda').show();
} else if (CurrentDay == 4 && (CurrentHrs >= 00 && CurrentHrs <= 24)) {
$('.msg').hide()
$('#stvrtok').show();
} else if (CurrentDay == 5 && (CurrentHrs >= 00 && CurrentHrs <= 24)) {
$('.msg').hide()
$('#piatok').show();
} else if (CurrentDay == 6 && (CurrentHrs >= 00 && CurrentHrs <= 24)) {
$('.msg').hide()
$('#sobota').show();
} else if (CurrentDay == 0 && (CurrentHrs >= 00 && CurrentHrs <= 24)) {
$('.msg').hide()
$('#nedela').show();
} else{
$('.msg').hide()
$('#no_del').show();  
}

var weekday = new Date();
weekday[0]=  "Nedeľa";
weekday[1] = "Pondelok";
weekday[2] = "Utorok";
weekday[3] = "Streda";
weekday[4] = "Štvrtok";
weekday[5] = "Piatok";
weekday[6] = "Sobota";

var n = weekday[tomorrow.getDay()];
document.getElementById("nextDay").innerHTML = n;

var jq211= jQuery.noConflict();

</script>

Thank you for your help.

10
  • It looks like you're importing jQuery at least twice, which is never ever a good idea. Commented Nov 16, 2020 at 13:48
  • But When I deleted script url from this code it did not work. Commented Nov 16, 2020 at 13:52
  • Describe "didn't work." Were there errors in your console? Keep in mind that when you use .noConflict(), it clears jQuery such that you can no longer use $. Commented Nov 16, 2020 at 13:55
  • @Marc yes there are some errors you could check it here delivery.beaboutburger.sk ...Im newbie in js so I could not do it very well. Commented Nov 16, 2020 at 13:56
  • @Marc on that url there is a adress field where you could check if your adress is in delivery area. Under intro there is orange line with 11 to 21 00 time. If I remove jquery from there it displays all lines as you could see in HTML code. If jquery is there, delivery checker does not work. Commented Nov 16, 2020 at 13:57

1 Answer 1

1

If anyone have the same problem I have solved this problem by editing code mentioned in steps bellow.

  1. I have removed code bellow due to a double call of jquery.

    <script>$.noConflict();</script><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

  2. I have replaced all $ symbols with jQuery

Now I have 0 console errors and everything works fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.