If have a variable data = '<div>... <button id="remember"> ... </button> ...</div>', is it possible to apply the .button(); method to a button inside that variable?
I’ve tried the following:
$('#remember', data).button();
but that doesn’t work. After that I just do $(data).dialog();, which works.
I’ve come with a workaround and that’s to append the variable data to the document, call the .button() and then call the .dialog(), but appending and removing dialog’s divs on the document doesn’t seems right.
You can do it using
.find(selector)and.end()like thisYou can see a quick demo here
For a breakdown of how this works:
$(data)– Creates a document fragment out of your string.find("#remember")– Locates the<button>inside.button()– Creates the jQuery UI button effect on that element.end()– Returns the previous set selector, effectively$(data).dialog()– Creates a dialog on the whole data element, since that’s where.end()puts the chain.