Search code examples
htmlfindhidden-field

Can I use HTML to add hidden text that still gets counted by ctrl+F?


I have a string of 1s and 0s that I want to have people count. However, to separate those people who are actually counting from those who are "cheating" by using ctrl+F, I'd like to include a few extra 1's that do not appear to people but would get counted if someone was using ctrl+F.

In other words, I'd like something to be displayed like this: 1 0 1 1
....but actually have two extra hidden 1's so anyone counting would see three ones but anyone using ctrl+F would report five ones (3 displayed + 2 hidden).

Is it possible to use HTML to have hidden text that isn't displayed but is counted by ctrl+F?

Here's what the code looks like right now.

Count the number of &quot;ones&quot; below:&nbsp;<br />
<br />
1 1 1 0 1 0 0 0 1 0 1 1 0 0 0 0 1 0 1

I'm new to both HTML and HTML StackOverflow. Thanks so much in advance for any help you might offer!


Solution

  • You can hide the hidden numbers by using a combination of absolute/fixed positioning and top/left translation.

    Example:

    .hidden {
       position: fixed;
       top: -9999px;
       left: -9999px;
    }
    <span class="hidden">1</span>
    <span>1</span>

    It might be easier to grok if you look at this codepen.

    You will physically see 8 1s in the browser, but CTRL + F shows 9.

    Inline Style Example

    <span style="position: fixed;top: -9999px;left: -9999px;">1</span>
    <span>1</span>