I have a XML file that contains
<car>
<id>123</id>
<sunroof>FALSE</sunroof>
<service>TRUE</service>
</car>
The following code only works if I wrap TRUE inside quotes e.g (service == "TRUE")
var service = tis.find("service").text();
if(service === TRUE){
var service_tag = '<a title="Service" href="">Service</a>'
} else {
var service_tag = '';
}
Without quotes javascript will try to interpret TRUE
as a value / expression. There is no value TRUE
natively defined in javascript. There is true
but javascript is case sensitive so it won't bind TRUE
to true
.
The value you get back from text()
is a string
primitive. Writing "TRUE"
gives you back the string
"TRUE"
which does compare succesfully with the value service
JavaScript boolean true
and false
are lower case.
Set service equal to this, so JavaScript will be able to interpret your values:
var service = tis.find("service").text().toLowerCase();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With