ycliper

Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
Скачать

What is $document ready function in jquery

Автор: kudvenkat

Загружено: 2015-03-18

Просмотров: 325439

Описание: Link for all dot net and sql server video tutorial playlists
   / kudvenkat  

Link for slides, code samples and text version of the video
http://csharp-video-tutorials.blogspo...

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
   / @aarvikitchen5572  

In this video we will discuss
1. What is $(document).ready(function() in jquery and when to use it
2. Difference between $(window).load and $(document).ready

$(document).ready is a jQuery event. It fires as soon as the DOM is loaded and ready to be manipulated by script. This is the earliest point in the page load process where the script can safely access elements in the page's html dom. This event is fired before all the images, css etc.. are fully loaded.

The following example works, because the jquery code that adds the event handler to the button is inside the ready() function, which ensures that the DOM is fully loaded before this piece of code is executed, so the JavaScript can find the button element in the DOM and adds the click event hanlder.

[html]
[head]
[title][/title]
[script src="Scripts/jquery-1.11.2.js"][/script]
[script type="text/javascript"]
$(document).ready(function () {
$('#button1').click(function () {
alert('jQuery Tuorial');
});
});
[/script]
[/head]
[body]
[input id="button1" type="button" value="Click Me" /]
[/body]
[/html]

In the following example, we have removed the ready() method. When you click the button now, you don't get the alert. This is because the jQuery code is present before the button element, so by the time the jQuery code is executed the button element is not loaded into DOM.

[html]
[head]
[title][/title]
[script src="Scripts/jquery-1.11.2.js"][/script]
[script type="text/javascript"]
$('#button1').click(function () {
alert('jQuery Tuorial');
});
[/script]
[/head]
[body]
[input id="button1" type="button" value="Click Me" /]
[/body]
[/html]

To make this example work, you have 2 options
1. Place your jQuery code in $(document).ready function OR
2. Place your script at the bottom of the page just before the closing [/body] element

$(window).load event fires when the DOM and all the content on the page (images, css etc) is fully loaded. Since the window load event waits for images, css etc to be fully loaded, this event fires after ready event.

The following example proves the above point. When you run the page with the following script, notice that the alert in ready function is displayed before the alert in load function.
[script type="text/javascript"]
$(window).load(function () {
alert('Window loaded');
});

$(document).ready(function () {
alert('DOM Loaded and ready');
});
[/script]

In most cases, the script can be run as soon as the DOM hierarchy has been fully constructed. So ready() is usually the best place to write your JavaScript code.

However, in your application there could be scenarios where you should be using $(window).load over $(document).ready. For example, let's say we want to display the actual image dimensions (Height and Width). To get the actual image dimensions, we will have to wait until the image is fully loded, so the jQuery code to get the height and width should be in $(window).load event.

Example : If you use $(document).ready() instead of $(window).load() the height and width will be displayed as 0.
[html]
[head]
[title][/title]
[script src="Scripts/jquery-1.11.2.js"][/script]
[script type="text/javascript"]
$(window).load(function (){
$('#div1').html("Height = " + $('#Image1').height()
"[br/]" + "Width = " + $('#Image1').width())
});
[/script]
[/head]
[body]
[div id="div1"][/div]
[img src="Chrysanthemum.jpg" id="Image1" /]
[/body]
[/html]

Не удается загрузить Youtube-плеер. Проверьте блокировку Youtube в вашей сети.
Повторяем попытку...
What is $document ready function in jquery

Поделиться в:

Доступные форматы для скачивания:

Скачать видео

  • Информация по загрузке:

Скачать аудио

Похожие видео

Benefits of using CDN

Benefits of using CDN

jQuery each function

jQuery each function

jQuery DOM manipulation methods

jQuery DOM manipulation methods

What is JSON

What is JSON

Кремль готовится к штурму / Переброска элитных подразделений

Кремль готовится к штурму / Переброска элитных подразделений

jQuery tutorial for beginners

jQuery tutorial for beginners

CI/CD — Простым языком на понятном примере

CI/CD — Простым языком на понятном примере

Почему Кошки Вдруг ЗАЛЕЗАЮТ На Вас? (Причина шокирует)

Почему Кошки Вдруг ЗАЛЕЗАЮТ На Вас? (Причина шокирует)

Что такое теория относительности, 1964 год

Что такое теория относительности, 1964 год

Математик и черт

Математик и черт

jQuery class selector

jQuery class selector

География Уральских Пельменей - Панама – Уральские Пельмени

География Уральских Пельменей - Панама – Уральские Пельмени

17 Ходов ПЕШКАМИ Подряд!В Психбольнице ему ЗАПРЕТИЛИ Шахматы. Бессмертная Партия Пешек

17 Ходов ПЕШКАМИ Подряд!В Психбольнице ему ЗАПРЕТИЛИ Шахматы. Бессмертная Партия Пешек

Nginx — Простым языком на понятном примере

Nginx — Простым языком на понятном примере

jQuery in One Video | Explained in EASIEST WAY

jQuery in One Video | Explained in EASIEST WAY

Первый “Баг” в Истории - и Женщина, Которая Изменила Программирование

Первый “Баг” в Истории - и Женщина, Которая Изменила Программирование

Difference between $ each and  each

Difference between $ each and each

Комедийная короткометражка «Альтернативная математика» | Озвучка DeeAFilm

Комедийная короткометражка «Альтернативная математика» | Озвучка DeeAFilm

Селектор элементов jQuery

Селектор элементов jQuery

Учебник JavaScript №2 | Что такое DOM? | Объектная модель документа

Учебник JavaScript №2 | Что такое DOM? | Объектная модель документа

© 2025 ycliper. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]