How to upgrade the code for the collapse — items to each new item was substituted with a new id?

Hi! Tell me how to do this "cycle", probably it can be called so. In the layout there are two blocks within which there is a hidden text is made using the bootstrap collapse. To the event of disclosure of unit linked change the text (read More/Hide). But is there a unique identifier for each block. If blocks was limited - it would be possible for each register id and for him to hang event. But elements is a lot, so the need to systematize the addition of id for the new item, and a bunch of id c data element. Now for the two blocks of code in js like this:
$('#toggle-cat-desc').on('show.bs.collapse', function(){
$(this).next().html('Hide');
});
 $('#toggle-cat-desc').on('hide.bs.collapse', function(){
$(this).next().html('read More');
});
 $('#toggle-cat-desc2').on('show.bs.collapse', function(){
$(this).next().html('Hide');
});
 $('#toggle-cat-desc2').on('hide.bs.collapse', function(){
$(this).next().html('read More');
 });

Help reference on solutions,if met or please tell me how to implement. Understand that you need to add a variable number and in a cycle to add. But knowledge of js is not enough(
July 8th 19 at 16:26
1 answer
July 8th 19 at 16:28
Solution
Just take the General class

$('.toggle-cat-desc').on('show.bs.collapse', function(){
$(this).next().html('Hide');
 }).on('hide.bs.collapse', function(){
$(this).next().html('read More');
 });
I guess I needed to accompany your question, the html code, I do not think.. if you directly from bustrapa to take - there's also the thing that the item reveals - set the attribute data-target with id of element that will be revealed ( that is, obtained data-target="#toggle-cat-desc"). getbootstrap.com/javascript/#collapse
Toli just the bootstrap has not demonstrated that it is possible to use class instead of id for multiple use on a page, Tolley, you can use the id only.. - cullen.Ebert57 commented on July 8th 19 at 16:31
: Yes, bootstrap is needed ID and set those ID - the task of the backend. You also have to implement its function (to change text), it is sufficient to add all the elements the same class and use similar code. - Lulu_Zulauf71 commented on July 8th 19 at 16:34
AAA))) thank you very much!)) - cullen.Ebert57 commented on July 8th 19 at 16:37

Find more questions by tags BootstrapJavaScriptjQuery