Jquery UI Dialog open on if condition

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Jquery UI Dialog open on if condition



I am creating a little game in jquery, where I want to show the user a little box, if they won the game.



The condition here is (correctcards ==10)
I tried to call dialog on it but it wont work.


(correctcards ==10)



Can anyone tell me why?



(I also aready tried to create a new div, when correctcards turn 10 and call dialog on it then, but it doesnt work as well)




if (correctCards == 10)
endTime = new Date().getTime();
time();
console.log('Spiel endet');
$('#myDialog2').dialog(
autoOpen: true,
modal: true,
resizable: false,
draggable: false,
buttons:
'Next Level': function()
$(this).dialog('close');
,
'Close': function()
$(this).dialog('close');
,

)


<div id="myDialog2">You won</div>




1 Answer
1



You need to create the dialog outside of your if.


if




$('#myDialog2').dialog(
autoOpen: false,
modal: true,
resizable: false,
draggable: false,
buttons:
'Next Level': function()
$(this).dialog('close');
,
'Close': function()
$(this).dialog('close');
,

);

var correctCards = 10;

if (correctCards == 10)
console.log('Spiel endet');
$('#myDialog2').dialog('open');


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script
src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"
integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU="
crossorigin="anonymous"></script>
<link href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css">
<div id="myDialog2" style>You won</div>





that was easy! I almost feel bad for bothering you Thank you!
– Nina
Aug 10 at 20:20





You're welcome. Would you mind upvoting andaccepting the answer?
– gforce301
Aug 10 at 20:29






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard