Peppered Lemons Peppered Lemons - 1 year ago 77
jQuery Question

Creating a dialog JQuery Mobile

I am trying to create a dialog with

Jquery mobile
. I have tried to refer to the accepted answer in this SO question but it didn't work for me.

Here is my code:

<div data-role="page" id="first">
<!-- Code -->
<div id = "dialog" data-rel="dialog">
<div id = "errorText"></div>
<button id = "closeDialog">OK</button>

And here is the JS to make it (inside a function):

//Nothing checked. Cannot continue. Add error message to div
$('#errorText').html("You must check the checkbox next to \"I Agree\" to continue");
//Open Dialog

When the code to create the dialog is reached nothing happens. Suggestions?

Answer Source

The dialog should be a separate page div which you can load via Ajax or include in your HTML. Here is an example.

<!DOCTYPE html>
    <title>Page Title</title>
    <link rel="stylesheet" href="" />
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>
<div data-role="page">
    <div data-role="header">
    <div data-role="content">
        <p><a href="dialog.html" data-rel="dialog" data-role="button">Is this a question?</a></p>
<div data-role="page" data-url="dialog.html">
    <div data-role="header">
    <div data-role="content">
        <p>Is this an answer?</p>