Главная » 2011 » Июль » 15 » jQuery. Проверить существование элемента на странице
01:33
jQuery. Проверить существование элемента на странице
Для того, чтобы проверить существует или нет заданный элемент, можно использовать 2 способа. В основе всего, лежит тот факт, что jQuery селекторы возвращают массив и мы можем искать его длину. Даже если найден только 1 элемент (когда мы конкретный элемент ищем) то размер ответа будет равен 1.

Способ первый - стандартный:
if($("#findID").length>0) {
// exists
}
//еще проще:
if($("#findID").length) {
// exists
}
// Еще вариант:
if($('#findID')[0]) {
// exists
}

Способ второй - удобный (создадим пользовательскую функцию exists() ):
// Один раз объявляем функцию, потом используем так, как в примере
jQuery.fn.exists = function() {
return $(this).length;
}
// Пример использования:
if($("#findID").exists()) {
// exists
}

Можно и так:
jQuery.exists = function(selector) {
return ($(selector).length > 0);
}

// Пример использования:
if ($.exists(selector)) {
// exists
}
Просмотров: 76527 | Добавил: Sergey Saenko | Рейтинг: 0.0/0
Всего комментариев: 9
9 BradliMar  
0
банк москвы рефинансирование кредитов https://xn--d1abkf4ap.xn--80aswg/city/arkhangelsk/ быстрые кредиты без справок и поручителей
срочно нужен кредит с открытыми просрочками
https://кредит.сайт/city/kurgan/
дали банкhttps://кредит.сайт/city/yoshkar-ola/
взять сумму кредитакредит под залог автомобиля банкиhttps://кредит.сайт/zaimy/contact/
https://кредит.сайт/city/60-zaym-onlayn-pay-ps.html


иск взыскание займа
https://кредит.сайт/city/volzhskiy/page/2/

договор займа между юридическими лицами образец

8 Doradoumn  
0
hi!

7 Michaeldon  
0
Forex

6 qpoesya4  
0
Вот сижу и не знаю что делать, совсем скоро рождественские праздники и я не очень хочу проводить их только дома.
Я хочу каких то новых ощущений и увлечений, вспомнила вот, что давно не каталась на лыжах, думаю купить абонимент))
В новогодний вечер, я решила остаться дома, у нас наконец то семейный празник))), планирую готовить блюда русской кухни,
все простенько, по родному и без выпенжрежа.

Поделитесь своими планами, чем вы собираетесь заниматься в новогодние каникулы?

5 lscuqvdctel  
0
Meine Erfahrungen vom 5 Juni 2008

kalimera

Sie lieben operative Verschönerung?
erfahrungen femmestyle klinik
Niemand operiert besser Fettabsaugung
Warum also noch suchen?

Laden Sie die Femmestyle Webseite und bekommen Sie alle Informationen über

http://www.femmestyle.de/ - Facelift OP
Ein super Tip von tortenfischmauifemmealledomains 428
gxis revido

4 Cecileendope  
0
инфопродукт

3 boubsWedsfuby  
0
After getting more than 10000 visitors/day to my website I thought your interestabout.ucoz.ru website also need unstoppable flow of traffic...

Use this BRAND NEW software and get all the traffic for your website you will ever need ...

= = > > http://mass-autopilot-traffic.net

In testing phase it generated 867,981 visitors and $540,340.

Then another $86,299.13 in 90 days to be exact. That's $958.88 a
day!!

And all it took was 10 minutes to set up and run.

But how does it work??

You just configure the system, click the mouse button a few
times, activate the software, copy and paste a few links and
you're done!!

Click the link BELOW as you're about to witness a software that
could be a MAJOR turning point to your success.

= = > > http://mass-autopilot-traffic.net

2 DerbTilbore  
0
After getting more than 10000 visitors/day to my website I thought your interestabout.ucoz.ru website also need unstoppable flow of traffic...

Use this BRAND NEW software and get all the traffic for your website you will ever need ...

= = > > http://mass-autopilot-traffic.com

In testing phase it generated 867,981 visitors and $540,340.

Then another $86,299.13 in 90 days to be exact. That's $958.88 a
day!!

And all it took was 10 minutes to set up and run.

But how does it work??

You just configure the system, click the mouse button a few
times, activate the software, copy and paste a few links and
you're done!!

Click the link BELOW as you're about to witness a software that
could be a MAJOR turning point to your success.

= = > > http://mass-autopilot-traffic.com

1 Swealzeva  
0
TRAST

Имя *:
Email *:
Код *: