Determine whether a field contains text or an image using JS?

If I have a field that sometimes contains an image and sometimes text, is there a way to check, using javascript, whether a given card has an image or text?

Maybe something like this:

<div id="Field_Id">{{FieldName}}</div>


         var image_count = $("#Field_Id img").length /*counts the number of images inside the div*/
         if (image_count == 0) { }  /*do something */
         else if (image_count >= 1) { } /*do something else */



I don’t think you can use jQuery in Anki (not without loading it from somewhere, at least).

You actually can.
While Anki moved away from using jQuery itself, the scripts are still bundled and injected in the review/preview screens at least.

1 Like