`
<!--jQuery--><script src="//code.jquery.com/jquery-1.12.4.js"></script>
<!--jQuery UI--><script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<!--jQuery UI CSS--><link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
<script>
function Alert(a){
$("#p")[0].innerHTML = a;
return new Promise(resolve => {
$("#main").dialog({
autoOpen: false,
height: "auto",
width: 400,
modal: true,
resizable: false,
buttons: {
"Ok": () => {
$(this).dialog("close");
resolve(true);
}
}
});
});
}
</script>
<script>
$(document).ready(function(){
await Alert("test");
});
</script>
<div title="Message!" id="main">
<p id="p"></p>
</div>
`
I’m wanting it to open a popup with the popup title of Message! and with the text of test.
I’ve tried so many things to fix this but I can’t.
I’ve come to the conclusion that it’s not selecting the elements properly.
3
Answers
Here is what I suggest:
The first thing I noticed is that there is no
async
on the left of function on your document ready. Try addingasync
and see if it solves the problemOr may by try to combine that 2 script tags into one
If it still doesn’t work, try logging it out with
console.log()
or regularalert()
on your value, see if it’s even return something at all. Maybe that$("#p")
doesn’t need the first index to be accessible because it is an id, not a classThat’s not correct, your code is working fine. Just that the dialog is not opened because
autoOpen
is set tofalse
.I tried this code, hope it helps:
(also I don’t think you need Promise)
Just one thing not related to your error though just informing you so you will remember this, this code is actually not right
The await keyword is only valid inside async functions within regular JavaScript code.
Just rewrite right way… hope it helps!
Any questions, just ask and I’ll answer in the comments.