-2
I’m trying to check a value in JSON to see if it’s null
value containing an image link. But when there is a link it returns an error:
Uncaught Error: Syntax error, unrecognized expression:
I’m using it properly?
var cardapiojson = "https://api.sheety.co/1a888dce-0342-4f9a-9bb6-b0e132d4b33f";
$.getJSON(cardapiojson, function(data) {
$(data).each( function (index) {
var itemImage = data[index]['img'];
console.log($(itemImage).val());
I know the mistake is in .val()
because when I comment on the console.log($(itemImage).val());
the site mounts normally.
And what I hoped to get from
$(itemImage).val()
?– Woss
itemImage is the value and not an element, so the error. just do console.log(itemImage);
– Fernando Valler
To check if it is null, just do
if(!itemImage){ // é null }
– Sam
That’s right @Sam. Thanks for the help. I looked elsewhere and everyone had to use . val() to find out if it was null.
– Mauricio Santos
.val() is to get value form elements
– Sam