Search code examples
jqueryasp.net-mvcjquery-selectorsjquery-dialog

Why does jquery need a selector for a ui dialog


I understand that jquery needs a selector to work with it like a class="x" on all links with class="x".

But what I do not understand is why does jquery need a selector like #dialog that points to a div because the dialog is doing nothing with the div.

In my opinion a window/dialog should have nothing to do with a div because the dialog is over all other ui elements.

sample:

<div id="dialog"> what is that div for?</div>
$('#dialog').dialog({...

Solution

  • The dialog element is acting as a container. When you open the dialog, it displays the contents of that container. You can always dynamically generate the content and display that, but using a container allows you to define the content first (and say, hide it), before you want to display/render it.