Chris Levine
Chris Levine

Reputation: 273

JQuery fadeout fading out too fast

I am trying to get a paragraph tag to fade out over 10 seconds, however it is fading out much faster than the intended 10 seconds.

<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>

<p>
    If you click on this paragraph you'll see it just fade away.
</p>
<script type="text/javascript">
    $("p").click(function () {
        $("p").fadeOut("10000");
    });
</script>

Upvotes: 8

Views: 5201

Answers (2)

adeneo
adeneo

Reputation: 318182

Drop the quotes to make it work with milliseconds, otherwise it will just use the default value, as "10000" is a string and not a time value, and it's not an accepted string like "slow" or "fast".

$("p").click(function () {
    $("p").fadeOut(10000);
});

Also, I like to reference things within scope like this :

$("p").on('click', function () {
    $(this).fadeOut(10000);
});

FIDDLE

Upvotes: 24

bretterer
bretterer

Reputation: 5781

Remove the quotes around the fadeout time. only quote around fadeout if you are using things like slow fast

$("p").click(function () {
    $("p").fadeOut(10000);
});

vs

$("p").click(function () {
    $("p").fadeOut("slow");
});

Fiddle with both examples

Upvotes: 4

Related Questions