0

I have a very simple piece of jquery code(sliding a piece of text up) based upon clicking on a div.

<script>
jQuery("#test").click(function () {
    jQuery(this).slideUp();
});
</script>

This works when the

<div id="test">some text</div>

is placed outside the main content of the page, so in the header or the footer, but it doesn't work when the <div id="test">some text</div> is placed within the content part.

I have searched the internet for a solution, but I cannot find a solution.

0

2 Answers 2

1

Make sure that code is executed on DOM ready:

jQuery(document).ready(function () {
    jQuery("#test").click(function () {
        jQuery(this).slideUp();
    });
});

Explanation: http://api.jquery.com/ready/

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

Comments

0

Use $(document).ready function as a wrapper for your code.

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.