I know there are various questions on jQuery chaining already, but I couldn't find an answer to this (probably rather simple) one. Forgive a newcomer to jQuery.
What I am looking for is a short way to apply different actions/events to the same object. More specific, I have the following code
$('#dlg').dialog('open').dialog('setTitle','Title').dialog('refresh','dlg.html');
Is there a way not to write .dialog
three times, but rather something along the lines of
$('#dlg').dialog(action 1, action 2, etc.)
? I am not familiar with the syntax yet, so I have no clue whether the arguments need to go in curly braces, with semicolons in between, or commas, or... Thanks for any help!
P.S.: The dialog in this example is a jQuery EasyUI dialog, if that makes any difference.
Update: Seeing that the answer to my question appears to be "no", what would be the best way to write the command above? I.e. is
$('#dlg').dialog('open')
$('#dlg').dialog('setTitle','Title')
$('#dlg').dialog('refresh','dlg.html')
better/worse in terms of efficiency compared to the line above, or is there yet another (better) way? Thanks for the quick help!
For what you're doing, there is basically no alternative. You could do something mad with a loop, but at the end of the day it's just adding complexity and unless you are doing this hundreds of times throughout your code, it's not worth the effort.
I assume you're aware you can pass an object containing various values in one call to init a dialog, as per the EasyUI docs:
$('#dd').dialog({
title: 'My Dialog',
width: 400,
height: 200,
closed: false,
cache: false,
href: 'get_content.php',
modal: true
});