i’m trying to use javascript code inside “jquery dialog” and my code executes more than once.
Simple example..
<div id='dialog'>
<script type="text/javascript">
$(document).ready(function () {
console.log('inside');
});
</script>
</div>
<script type="text/javascript">
$(document).ready(function () {
console.log('Dialog init');
$('#dialog').dialog();
})
</script>
And my output is:
- inside
- Dialog init
- inside
Well that makes sense then…
jQuery probably locates the contents of
#dialogto somewhere and the code inside gets executed again.Why is there JS in the
#dialogbox? Is it loaded with XHR? If not: move it to where the rest of the domready code is.Do you want an event to trigger when the dialog is shown? Is that why there is code in the dialog? If so, there is en event API for that: http://jqueryui.com/demos/dialog/#events