O
O
Oleg Fursa2015-10-01 12:13:12
JavaScript
Oleg Fursa, 2015-10-01 12:13:12

How can I make it so that only one element works when clicked, and not all at once?

Essence of the question: there are several blocks with text that is partially hidden, and when pressed, expands completely. But the problem is that instead of one, all unfold at once. How to make it so that only the clicked element works.

codepen.io/Oleg_Fursa/pen/xwgQBZ

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kovalsky, 2015-10-01
@Oleg_Fursa

$('.text-to-show').slideToggle(300);
Here you say "Expand all elements with class .text-to-show". Script and deployed.
Adjust the selector. For example$(this).prev(".text-to-show").slideToggle(300);

O
Oleg, 2015-10-01
@Screpka

$('.text-to-show').hide();
$('.open-link').click(function(){
  $('.text-to-show').slideToggle(300);
  var text = $(this).text();
  $(this).text(
  text == "[развернуть]" ? "[свернуть]" : " [развернуть]");
});

$('.text-to-show-two').hide();
$('.open-link-two').click(function(){
  $('.text-to-show-two').slideToggle(300);
  var text = $(this).text();
  $(this).text(
  text == "[развернуть]" ? "[свернуть]" : " [развернуть]");
});

Well and accordingly classes in html to change. ) The most wooden solution, since I practically don’t understand anything in js.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question