Q:

Store original text once

I have a simple function which gets the original text of a div, and changes this text when the user resizes the window (responsive site). When the user enlarges the window again, the original text must be shown. It's very simple, but i have a small problem.
function limitH2Text() {
        var origText = $(".result .right .mask").text();
        var width = $(window).width();
        if (width < 811) {
            $(".result .right .mask").each(function () {
                var $this = $(this);
                $this.text($this.text().slice(0, 75));
                $this.append('...').show();
            });
        } else {
            $(".result .right .mask").each(function () {
                $(this).text(origText);
            });
        }
    }

The console shows that the var origText contains text of three [.result .right .mask] divs. You see, the HTML is a repetition of [.result .right .mask]. So instead of (for example) 'hello this is the text', it shows 'hello this is the text hello this is the text hello this is the text'. When the user resizes, this grows exponential so the browser crashes. I can't figure out how to only once store the text of that one div?
Thanks for the help!

A:

Try this using .eq():
var origText = $(".result .right .mask").eq(0).text();

This will reduce the set of matched elements to the one at the specified index and store the text of that one div.

