user3047675
user3047675

Reputation: 82

Check if element exists on another page

Is there any way to check whether a certain element exists on another page (under the same domain) without pulling it into the current page using jQuery? I want to get the ID of an element on a different page. For example, there's index.html and index2.html. Now there's a div.foo on index2.html and I want to get its id. I would then pull that element into index.html if I think it's one that I'm looking for.

As it stands, I can use jquery .load() but as far as I understand it, it pulls the elements into index.html first. I think that would be a little redundant incase the div in question doesn't satisfy the requirements I need before I pull it into the current page.

So is there a way to check elements on a different page without pulling it into the page first? This is mainly academic though as I'm ready to use .load() when it comes down to it. I just don't like to do something unecessary when I can avoid it.

Upvotes: 0

Views: 592

Answers (2)

Bala
Bala

Reputation: 510

No , you can't. You should make ajax call like .ajax, .load, .get to read the content of index2.html.

Upvotes: 0

Volkan Ulukut
Volkan Ulukut

Reputation: 4218

There is no way that you can check a html file's contents with client-side scripting without getting it first. cause javascript works in the client's computer, who has no idea what index2.html might have.

BUT if that computer ever visited index2.html before, you can put that elements name on cookie and check it in index.html without loading it first.

Upvotes: 1

Related Questions