There is a code:

$('#close-carousel').click(function (e) { jQuery('#carousel1').hide(); }); 

Tell me, how can I set the range of identifiers from #carousel1 to #carousel30 and is it even possible in general?

    2 answers 2

    It is possible so:

     $('#close-carousel').click(function (e) { for(var i = 1; i<31; ++i) jQuery('#carousel'+i).hide(); }); 

    And you can carousel put all the carousel in one block and hide it.

      The best way is to assign the same CSS class to all the necessary elements. With this approach, you will not have to cycle through each click on the closing element of your carousel:

       function setReadyToCloseCarouselElements() { var lowerLimit = 1, upperLimit = 30; for (var i = lowerLimit; i <= upperLimit; i++) { $("#carousel" + i).addClass("ready-to-close"); } } setReadyToCloseCarouselElements(); $("#close-carousel").click(function (e) { $(".ready-to-close").hide(); });