You can add data attributes when creating the element
var panelHeading = $('<div />', {
'class' : 'panel-heading',
href : '#'+username+'PanelContent',
'data-toggle' : 'collapse',
'data-target' : '#'+username+'PanelContent'
});
using data()
stores the data internally in jQuery, it does not create HTML attributes, so it works rather poorly with attributes for things like Bootstrap