There are many divs on the same page with id-wrap, they have h3 and another div with text-class, which by default is display noun. It is necessary that by clicking on the h3 div-text it is in the wrap in which the h3 it clicked opened. I am writing a primitive jQuery script:

var wrap = $('#wrap'); wrap.find('h3').click(function(){ wrap.find('.text').slideToggle(); }); 

But for some reason, it only works with the first wrap, the rest you click and zero reaction ... Direct, on the right path ...

  • one
    many divs with idi-wrap are the reason. In accordance with the specification, id must be unique, so no one guarantees how elements with identical id will be processed. Use the class .wrap - Grundy

1 answer 1

many divs with idi-wrap are the reason. In accordance with the specification, id must be unique, so no one guarantees how elements with identical id will be processed. Use the class .wrap

And immediately it will be necessary to correct the mistake that all the wrappers are selected at once.

 var wrap = $('.wrap'); // все элементы с классом на странице wrap.find('h3').click(function(){ // здесь нужно идти отродителя с классом wrap $(this).closest('.wrap').find('.text').slideToggle(); }); 
  • Thank you very much. Have helped. I thought ID for js is better, but here it is. Thank you again. - overtheman
  • @overtheman, what is better? :-) better this concept is relative - Grundy
  • Yeah, I probably, as a person without a technical education, but with a humanitarian one, I understand the word “better”, quite differently. I thought to go to js more "soul" lies than to the class - =)) - overtheman
  • @overtheman, not, js absolutely spit class it or id - Grundy