Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery on page load event not working

Tags:

jquery

I want to my text fade in when page is loaded, i tried with this code-

 $(document).on("load", function () {
    $("#div1").fadeIn();
});

Why this not working? I'm using 3.1.1

like image 754
Tamas B. Avatar asked Mar 01 '17 20:03

Tamas B.


People also ask

How check page is loaded or not in jQuery?

Basically, the most reliable way to check if jQuery has been loaded is to check typeof jQuery — it will return "function" if jQuery was already loaded on the page, or "undefined" if jQuery hasn't been loaded yet.

What is the page load event in jQuery?

The load event occurs when a specified element has been loaded. This event works with elements associated with a URL (image, script, frame, iframe), and the window object. Depending on the browser, the load event may not trigger if the image is cached (Firefox and IE).

Which is the alternative to load event in Ajax?

Use $. ajax instead of . load function. But make sure you specify the dataType as html for the ajax function. .


1 Answers

You should be passing .on("load") on the window instead of the document:

$(window).on("load", function () {
    $("#div1").fadeIn();
});

Alternatively, you could call .ready() on the document:

$(document).ready(function () {
    $("#div1").fadeIn();
});
like image 191
Malcolm Avatar answered Nov 14 '22 21:11

Malcolm