jQuery Example - expandable tables To have expandable tables requires the HTML shown below in Output (where XXXXXX and YYYYYY are placeholders for actual data). The jQuery shown below converts the simplified input format to the output format. Input Output
expander XXXXXX information
**** jQuery solution $('table.expandable').each( function() { console.log('expandable table'); // constants var expanderImage = "expander"; var citationImage = " information"; // parse table components var id = $(this).attr('id'); var caption = $(this).find('> caption'); var body = $(this).find('> tbody'); var titleInfo = $(caption).attr('data-citation'); // table $(this).removeClass('expandable'); // citation var citation = $(citationImage).attr('title',titleInfo); // caption ?????????? brutal hack with bold tag var thisCitationImage = citationImage.replace('title=','title=' + id); var newCaptionText = expanderImage + ' ' + caption.text().trim() +'  '+ thisCitationImage; caption.addClass('expanderHeader expanded') .html(newCaptionText) .append(citation) ; // table body body.addClass('expanderContent expanded') .attr('data-topic', id) ; });