B
B
Boggdan2020-05-05 13:31:59
JavaScript
Boggdan, 2020-05-05 13:31:59

How to make sure that when you click on a certain object in a certain block, the site understands this?

I have blocks in which the content is the same, and when clicked, all blocks open (I have hide and show there). I need to open only the block that I click on.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dubolom Unicellular, 2020-05-05
@duboloms

Use index():

$(".div").on("click", function(){
  var index = $("div").index(this);
  // После чего вставь свой код который отвечает за показ и закрытие блока, только к селекторам 
  // прибавь .eq(index)
  $("div").eq(index).hide(); // eq метод выбирает элемент по индексу
});

Instead of div, the name of the block
Or read on the office. site in the article: https://api.jquery.com/index/

L
Lord_Dantes, 2020-05-05
@Lord_Dantes

After click function use this parameter and jquery action

N
n1ksON, 2020-05-05
@n1ksON

https://developer.mozilla.org/en/docs/Web/JavaScript...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question