I have the following code:
var $form = '',
$modal = '',
$submits = '';
function createModal() {
$modal = $.modal({
title: title,
closeButton: true,
content: content,
resizeOnLoad: true
});
$form = $modal.find('.form');
$message = $modal.find('.message');
$submits = $modal.find('.submit-button');
href = $form.attr('data-href');
}
Is there some way that I could add $form, $message and $submits to the $modal object as they are all related.
To associate data to a jQuery object, you may use the data function :
You usually need this because simply associate some properties to a jQuery object wouldn’t allow you to get the data back from another object wrapping the same element.
In your case, if you keep a reference to your object, you may simply do
So you keep only one clean reference to the whole thing and you may access
modal.$modalormodal.$form.