3

Хочу сделать так: Если у пользователя в имени и фамилии больше 20 букв, то лишнюю часть скрыть.

$text_length = $('.test_name').text().length;
if($text_length > 20){
// Хотелось бы чтобы лишние символы были скрыты
  $('.test_name').text('...');
 
}	
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h5 class="test_name">John Doe</h5>
<h5 class="test_name">Andrew Ivanov</h5>
<h5 class="test_name">Alexander Maslennikov</h5>
<h5 class="test_name">Christopher Robinson</h5>

1 ответ 1

9

Бесплатно, без смс, javascript и jquery:

.test_name {
  width: 100px;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
<h5 class="test_name">John Doe</h5>
<h5 class="test_name">Andrew Ivanov</h5>
<h5 class="test_name">Alexander Maslennikov</h5>
<h5 class="test_name">Christopher Robinson</h5>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.