I think this should fix it
const withinCooked = $(range.startContainer.parentNode).closest('.cooked');
Haven’t tested though.
I think this should fix it
const withinCooked = $(range.startContainer.parentNode).closest('.cooked');
Haven’t tested though.