开发者

How to detect a specific page load with javascript?

开发者 https://www.devze.com 2023-03-15 17:54 出处:网络
I have a gallery page with a table that has an id. Each table cell has an img element. How 开发者_运维问答do I test if the current page has a table and those img elements?

I have a gallery page with a table that has an id. Each table cell has an img element. How 开发者_运维问答do I test if the current page has a table and those img elements?

I tried:

if ($("#gallery-table img"))
{
alert("Gallery page");
}

but that code runs on every page even if the elements do not exist.


Try

if ($("#gallery-table img").length)
{
   alert("Gallery page");
}

jQuery is returning an object no matter what, so you'll need to see if anything exists in that object.

0

精彩评论

暂无评论...
验证码 换一张
取 消