I’m new to both Javascript and the framework jQuery.
Basically I’m trying to say that if the quantity is greater than 1 then don’t charge a fee. However if it is equal to 1 charge a fee. But I don’t know how to store the variables while using jQuery.
My thought was… (is this correct?)
var qty = $(".qty_item");
var price = $(".price_item");
var fee = "";
if (qyt==1) {
var fee = 250;
}
else {
var fee = 0;
}
I’ve noticed though that in some jQuery plugins they declare variables like so…
qty: $(".qty_item"),
price: $(".price_item")
Any help is much appreciated.
To get values from elements, you need to use the
$.val()method (assuming it’s an input element).So price would be 5 assuming the following HTML:
You could simplify your fee-finding logic by using a ternary operator too:
So if the value of our input (having the classname ‘element’) is greater than 1, fee will be 250. Else, fee will be the value of our input (having the id ‘price’).