0

My code for collapsible jquery div works on codepen and JSFiddle, but when I copy everything to my page (content adapted), the div does not expand. What am I missing, or where did I go wrong?

My script tags in the head are as follows:

<head>
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.0/jquery-ui.js"></script> 

    <script type="text/javascript">
        $(".header").click(function () {
            $header = $(this);
            $content = $header.next();
            $content.slideToggle(500, function () {
                $header.text(function () {
                    return $content.is(":visible") ? "Collapse" : "Expand";
                });
            });
        });
    </script>
</head>

And my content within the body:

<form method="post" action="sales_report.php" enctype="multipart/form-data">
    //multiple <input /> fields here
    <div class="container">
        <div class="header"><span>+Options</span></div>
        <div class="content">
            <h3>Designate the Column of:</h3>
            <p>Account Name</p>
            <input required type="number" name="sales_report_col_acc" id="sales_report_col_acc" value='1' />
            <p>Sale Amount</p>
            <input required type="number" name="sales_report_col_amt" id="sales_report_col_amt" value='2' />
            <p>Sale Date (optional)</p>
            <input type="number" name="sales_report_col_date" id="sales_report_col_date" value='3' />
            </br /> 
        </div>
    </div>
    <input type="submit" name="sales_report_submit" value="Go" />
</form>

Please advise on how to fix this? Am I missing something crucial that goes along with jquery.

1 Answer 1

3

You need to wrap your code inside ready handler:

$(document).ready(function(){
     //your code here
});

Or,

$(function(){
   //your code here
});
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.