Question about lightbox

How do you populate the lightbox using Ajax? Does the element have to have data attributes or can you define it in the JS script? Or can it do both?