K
K
kapai692015-02-14 19:32:45
JavaScript
kapai69, 2015-02-14 19:32:45

How to hide extra elements?

The organization has multiple phones

<span class="phone">8 (900) 123-24-01</span>
<span class="phone">8 (900) 123-24-02</span>
<span class="phone">8 (900) 123-24-03</span>
<span class="phone">8 (900) 123-24-04</span>
<span class="phone">8 (900) 123-24-05</span>
<span class="phone">8 (900) 123-24-06</span>

It is necessary to leave two phones, and hide the rest, and write View more, so that you can see the rest if you wish.
So how do you organize it better?
On the server, after the second iteration, mark phones as hidden.
Or, on the javascript client, count the number of elements with the phone class, and also hide the extra ones.
Or, can you suggest another more elegant way?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexey Nikolaev, 2015-02-14
@kapai69

Mark as hidden - on the server, show - through js. Also, if support for older browsers is not of great importance to you, you can get by with just js (show) + css (hide, use nth-of-child).

.phone:nth-of-child(2n+1) {
   display:none;
}

Using JS for hiding is a bad idea, because elements will be visible until the scripts are executed (there may be flickering and other troubles).

S
smoklew, 2015-02-14
@smoklew

you can name the classes differently, for example phone, phone1, etc. and do .hide()

R
Roman, 2015-02-14
@paradoxo

add the class "hidden" to hidden numbers, for example, with hiding via CSS. Well, and then using JS, remove the class when you click on "more"

S
Sasha Tkachenko, 2015-02-15
@AleksandrAndHABR

Hide everything except the first one, show all when hovering over the parent block, or show everything when clicking on the icon.
Please describe your requirements in more detail.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question