Reputation: 8161
My if function always return false when variable have space using
' '
My string is -
var Report = "Tab";
$(Report).text($(Report).text() + ' X');
if ($(Report).text() == "Tab X") {
}
else{
}
Upvotes: 0
Views: 145
Reputation: 12579
your effectively doing something like this: $('Tab')
which is not the correct jQuery.
try something like this for starters:
var Report = $("#tab"); // cache element with id="tab"
Report.text(Report.text() + ' X');
if (Report.text() === "Tab X") {
}
else{
}
Upvotes: 1
Reputation: 49817
this is not correct, cause you have no $('tab')
elements i assume :
var Report = "Tab";
$(Report)
your are creating an object from a string !?
also you are comparing htmlspecialchars with nothing so it always will be false your condition.
i suggest this:
var Report = "Tab";
Report.text(Report.text()+" X");
if (Report.text() == "Tab X") {
}
else{
}
Upvotes: 0
Reputation: 15087
is a HTML entity and you set it with text() which replaces &
with &
. Your element ends up with Tab X
, not with spaces
Upvotes: 1