0

I'm having difficulty getting jquery to work within a dialog box. I have the following code:

<html>
    <head>
    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js" type="text/javascript"></script>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script>
    $(function(){
        $('#dialog').dialog();
    });
    $('#switch').click(function(){
        $('#number1').hide();
        $('#number2').show();
    });
    </script>
<style>
#number2{
    display:none;
}
</style>
</head>
<body>
<div id="dialog" title="blank">
<div id="number1">
    <form>
        <p><input type="text" name="text"></p>
        <p><input type="radio" name="one" value="one">One</p>
        <p><input type="radio" name="one" value="two">Two</p>
        <p><input type="radio" name="one" value="three">Three</p>
        <p><input type="submit" name="submit" value="submit"></p>
        <p id="switch">click here to switch</p>
    </form>
</div><!--End of #1-->
<div id="number2">
    <h1>div number 2</h1>
</div><!--End of #2-->
</div>
</body>
</html>

I'm just trying to figure out why I cant get div #2 to show and div #1 to hide. I'm sure there's a simple solution, but I can't seem to find it. Thanks in advance for the help

1 Answer 1

1

You have to bind event in $(function(){...}); in document-ready function

$(function(){
    $('#dialog').dialog();

    $('#switch').click(function(){
       $('#number1').hide();
       $('#number2').show();
    });

});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.