Hello.

There is a PHP handler that replaces the HTML element when parsing with its custom one.

foreach($html->find('.hidewrap') as $value) { $value->outertext = '<div class="spoiler-wrapper"> <div class="spoiler folded"><span>'.$value->children(0)->plaintext.'</span></div> <div class="spoiler-text">'.$value->children(2)->plaintext.'</div> </div>'; } 

After that, the whole thing is given through json. Actually, what's the problem. CSS applies to these elements, but the js script does not want to be executed.

  $(document).ready(function() { $('.spoiler-text').hide(); $('.spoiler').click(function(){ $(this).toggleClass("folded").toggleClass("unfolded").next().slideToggle(); }); }); 

Thanks in advance for your reply.

    1 answer 1

    rtfm api.jquery.com/on

     $(document).on('click','.spoiler',function(){ $(this).toggleClass("folded").toggleClass("unfolded").next().slideToggle(); }); 
    • @Yura Ivanov, thank you very much! - evansive
    • By the way, could you tell me how to hide the whole element? $ ('. spoiler-text'). hide (); For not hiding. - evansive
    • @evansive is hiding. more important at what point. in question, your .spoiler-text is hidden not by a click, but after loading the page, i.e. immediately and once. demon - Yura Ivanov