读取javascript变量并输出css更改

I've got a page which dynamically updates a cart via javascript. I would like to show/hide div's based off changes made to the javascript, but any onlick or event listeners reset upon the form submit, so what I need to do is create a javascript script which checks the values posted to the cart and then selects styles based on that.

My thought was to do something like this:

if(my-item-name == 'i-SPEED 716') {
document.getElementById("716a").style.display = "none";
document.getElementById("716r").style.display = "inline";}

else {
document.getElementById("716r").style.display = "none";
document.getElementById("716a").style.display = "inline";}
};

Is there a better way to do this?

Assuming your getting the value of your cart items. You could try this format :

 if(cartItems.length > 0){

    /*do something....*/

    }else{

    /*do something else...*/

    }