Rewrite element displayed algorithm

Fixes bug 26304.