Reputation: 115
I know...this should be stupid simple but I am new to JQuery/JavaScript and this particular situation has me stumped. Most of what I do is plagiarized from studying snippets and just trying things over and over until I get the syntax right.
I have this line defined in a function:
$("#regularfee").text("25.00");
which of course allows me to have it displayed in my div "regularfee" in my html. This is working no problem.
All I want to do is at a later point within the same function set a different variable equal to the first.
I fully understand just saying: var newvar = oldvar and such...but when it is represented as above I can't seem to find the right syntax to make it happen. I promise...I have searched for a couple of hours but have not been able to find an example that works for me...please be gentle! LOL!
Additional info:
Here is a bit more detail...
$("#regularfee1").text("30.00"); // this displays just fine in my <div>
$("#regularfee").text("25.00"); // this displays just fine in my <div>
var regularfee = 25; // now *really* set the var...this is what I did not realize
var regularfee1 = 30;
// some other non-relevant code...
// I have another <div> in my html <div id=regselectedfee>
// and I have a conditional that sets regselectedfee based on the conditional
// now I want to have the <div id=regselectedfee> display its newly set value.
// How do I set $("#regularselectedfee"). ??? to show either regularfee or regularfee1 variables?
What is the syntax of this line to make that happen?
I hope I'm stating this a bit more clearly...
Upvotes: 0
Views: 4609
Reputation: 358
Hi you can do it like this
var somevalue = 25.00;
$("#regularfee").text(somevalue);
then you can change the variable value after like this
somevalue = 30.00;
or you can do
var another = somevalue;
Upvotes: 0
Reputation: 12121
This is the syntax: mynewvar=$("#regularfee").text();
(assuming $("#regularfee")
has no children elements; if it does, try $("#regularfee:first").text()
; see the jQuery .text()
method documentation for detail).
Though it may be faster to do something like this:
var regular_fee="25.00",
mynewvar;
$("#regularfee").text(regular_fee);
mynewvar=regular_fee;
Upvotes: 0
Reputation: 1833
Do you mean something like this?
var oldvar = "25.00";
$("#regularfee").text(oldvar);
var newvar = oldvar;
Upvotes: 1