How can I reveal/hide all cloze deletions at once?

Just like the description, how can i achieve this, thanks a lot :slight_smile:

I already know how to create multi cloze deletions with same cloze number, what I don’t know is when I review the card, how can I toggle the answer of the clozed content before hit the rate button.

https://docs.ankiweb.net/editing.html#cloze-deletion

1 Like

I’ve read the document, but I couldn’t find the solution.

You can also elide multiple sections on the same card. In the above example, if you change c2 to c1, only one card would be created, with both Canberra and 1913 hidden. If you hold down Alt (Option on a Mac) while creating a cloze, Anki will automatically use the same number instead of incrementing it.

maybe my question is unclear, I updated it.

Like other users, I vaguely understand what you want.
Try the following add-ons:
1990296174
1784155610
838763277
The forum does not allow me to leave a full link. Perhaps because I recently registered (it’s strange because these are links to internal resources ANKI)

Thanks, I will try this addons, I guess they all create their own note types to realize the functionality, I wonder if I can do similar thing using the standard built-in ‘Cloze’ note type.

I’ve tried the 1990296174 addon, it has the ability to relveal all clozes at once while reviewing, but I think it’s heavy for me to use an addon for a function like this.
I still don’t know how to reveal/hide all clozes when I’m reviewing the card using just the built-in ‘Cloze’ note type.

Maybe try something like this:

<button onclick="toggleAnswer()">Toggle Answer</button>

<script>
var currentCloze = document.querySelectorAll(".cloze");
var nextAction = "showCloze";

function toggleAnswer() {
  for (var i = 0; i < currentCloze.length; i++) {
    if (nextAction === "showCloze") {
      currentCloze[i].innerHTML = currentCloze[i].getAttribute("data-cloze");
    } else {
      currentCloze[i].innerText = "[...]";
    }
  }
  nextAction = (nextAction === "showCloze") ? "hideCloze" : "showCloze";
}
</script>
1 Like

Thank you very much.
This is exactly what I want.

I’m glad to hear that!

This is another slightly more complex version of the script, which works better in case you ever use placeholders/hints in your clozes (e.g., {{c1::cloze::hint}}).

<script>
var currentCloze = document.querySelectorAll(".cloze");
var nextAction = "showCloze";

for (var i = 0; i < currentCloze.length; i++) {
  currentCloze[i].setAttribute("data-original-content", currentCloze[i].innerHTML);
}

function toggleAnswer() {
  for (var i = 0; i < currentCloze.length; i++) {
    if (nextAction === "showCloze") {
      currentCloze[i].innerHTML = currentCloze[i].getAttribute("data-cloze");
    } else {
      currentCloze[i].innerHTML = currentCloze[i].getAttribute("data-original-content");
    }
  }
  nextAction = (nextAction === "showCloze") ? "hideCloze" : "showCloze";
}
</script>
2 Likes

I find it works on the desktop(macOS) app, but doesn’t work on Ankidroid, still don’t know why.

Desktop
Feb-01-2024 09-41-18

Ankidroid
ezgif-1-cb2eb55dcf

What version of AnkiDroid are you using?

The code relies on the data-cloze attribute, which is a relatively new addition to Anki and might not have been integrated into official AnkiDroid releases yet. For example, I believe the data-cloze attribute might still be absent in AnkiDroid 2.16. I tested the script on AnkiDroid 2.17alpha17, and it seems to work fine.

If I recall correctly, the developers mentioned that a beta for version 2.17 should be available in about two weeks. If you’re feeling adventurous and want to try an alpha release, you can find it here: Releases · ankidroid/Anki-Android · GitHub

1 Like