I currently have a (fairly sizable) JavaScript file which is used to animate some elements on a page. There are four \'sets\' of scripts used on the page, each set contains
I'll give you an example for the first block provided. There you have #tutorial-toc-step-01
. So, give all similar elements a class, for example, tutorial-toc-step-c
as well as save the number in additional field, for example, data-stepnum='01'
. Then, the beginning of the code would like like that:
/* ToC List Togglers */
jQuery(document).ready(function() {
jQuery('.tutorial-toc-step-c').click(function() {
var stepnum = $(this).data('stepnum');
if ( jQuery('.tutorial-glyph-check-step-'+stepnum).hasClass('glyphicon-unchecked') && !jQuery('#tutorial-body-step-'+stepnum).hasClass('in') ) {
jQuery('.tutorial-glyph-check-step-'+stepnum).removeClass('glyphicon-unchecked'),
jQuery('.tutorial-glyph-check-step-'+stepnum).addClass('glyphicon-check'),
...
I think, the idea is understandable. You'll have to rewrite each of those four blocks in a similar way.
By the way, was it intended that the first and the second code is absolutely the same except the clicked element id
?