jeudi 31 mai 2018

JavaScript Statements Flagged as Not a Function?

I have an JavaScript if..else statement inside of a block to hide or show two buttons:

/* Toggle Revert or Complete buttons based on order status */

if (!status1 || status2 == "wc-completed" ) { // Status check working
  (function() {
    $(document.getElementById(idDIVOrder)).querySelector('form.complete-order-cred').style.visbility = "hidden";
    $(document.getElementById(idDIVOrder)).querySelector('form.revert-order-cred').style.visbility = "show";
  })();
} else if (!status1 || status2 == "wc-processing" ) {
  (function() {
    $(document.getElementById(idDIVOrder)).querySelector('form.revert-order-cred').style.visbility = "hidden";
    $(document.getElementById(idDIVOrder)).querySelector('form.complete-order-cred').style.visbility = "show";
  })();
} else {
  console.log("Hide or display buttons not working! Order has a status of " + status1 + " and " + status1);
}

I'm getting the error "Uncaught TypeError: $(...).querySelector is not a function", which also occurs if I place the .querySelector statements inside the if and else without functions.

What's the right way to declare JS functions here?

Aucun commentaire:

Enregistrer un commentaire