Reputation: 2058
I am testing the following JS conditional in my console however it is returning "undefined" when it should be executing a logging to console. Can someone please explain why the following doesn't work? I can individually test jQuery("li.category652 a").text() and it returns "Signage" but I just can't get it to work in an if statement in console.
if (jQuery("li.category652 a").text() === "Signage") {
console.log("success");
}
else {
console.log("fail");
}
I can copy and paste that code into the console of any webpage that isn't the one I'm working on locally and you will get "fail" because the DOM element jQuery is looking for doesn't exist. If I do it on the webpage with that DOM element then all I get is "undefined" and no success or fail message.
That specific jQuery reference is unique to a local site I am working on but the above conditional can be treated as if it said this:
if ("Signage" === "Signage") {
console.log("success");
}
else {
console.log("fail");
}
Upvotes: 0
Views: 470
Reputation: 1075099
however it is returning "undefined"
If you look just above the undefined
, you should see success
or fail
(unless jQuery isn't loaded at all, in which case you'll see an error):
Here's a successful example from this page:
Upvotes: 3