Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function ($) {
- // Add class to children only.
- $('.js-form-item:has(span.field-prefix)').addClass('is-child');
- // Use a counter to be able to move children to the right container.
- let counter = 0;
- $(".js-form-item").each(function(){
- if(!$(this).hasClass('is-child')) { //Parent: Add class and container
- counter++;
- $(this).addClass('parent-' + counter + ' js-parent');
- $(this).append('<div class="container-' + counter + ' js-container"></div>')
- }
- else { // Child: move them to the parent's container.
- $('.container-' + counter).append($(this));
- }
- });
- // Hide all children.
- $('.js-container').slideUp();
- // On parent click, hide all other containers and show the current one.
- $('.js-parent').click(function(e){
- var isChild = $(e.target).closest('div').hasClass('is-child');
- //console.log(current.hasClass('is-child'));
- if (!isChild){
- $('.js-container').slideUp();
- $(this).find('.js-container').slideDown();
- }
- return false;
- });
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement