Consider:
var ret = { valid: true, message: "" };
var prtime = $(".ptime").val();
var ctime = $(".ctime").val();
if ($(prtime).length == 0 || $(ctime).length == 0) {
ret = { valid: false, message: "" };
}
$(prtime).length
When I run this, I get 0, even when I fill some words in prtime. And when I do $(".ptime").val().length then it shows me the length.
What have I done wrong with that code?
prtimeis a plain string. Don’t wrap it as a jQuery object.To get the amount of characters in the string, have: