-1

I have a popup window that needs to be hidden if there was a click on my site or on the Iframe. What I would like to do is write a method like this:

if(click on my site || click on Iframe){
    hide window
}    

I've tried this code but it doesn't work:

if($(document).click()===true  || $("#clientframe").contents().find(document)===true)(function(){
    $("#img-window").hide();
});
Cody Cook
  • 3
  • 8
  • how about simle to add a new fuction? – D.Dimitrioglo Jul 01 '16 at 17:48
  • 2
    it's not clear that what you are trying to achieve – Pranav C Balan Jul 01 '16 at 17:48
  • What is `.method()`? – guest271314 Jul 01 '16 at 17:58
  • I would like to have a chunk of code that can be executed if any of the conditional statements are met – Cody Cook Jul 01 '16 at 17:59
  • .method is just pseudocode for some generic jquery method – Cody Cook Jul 01 '16 at 18:00
  • If a jQuery selector results in a collection of elements then the chain is executed, if not then it isn't (and fails silently). It feels like you should be using [`filter()`](http://api.jquery.com/filter), or similar, but without some precision in what you want to do, and how, and based upon what (even a very simple real-world example should suffice) it's very hard to answer this question in an appreciable manner. – David Thomas Jul 01 '16 at 18:02
  • But `jQuery` object is always evaluated as `true`... – Rayon Jul 01 '16 at 18:05
  • @Rayon, a jQuery object is always evaluated as true, regardless of the length of the contained collection, but methods don't always return that object, for example [`text()`](http://api.jquery.com/text/), when used without an argument, returns a String; [`is()`](http://api.jquery.com/is/), when used *with* an argument returns a Boolean. – David Thomas Jul 01 '16 at 18:07
  • @DavidThomas — True.. My comment was targeting OP about his post. Provided example does not clarify his point.. – Rayon Jul 01 '16 at 18:09
  • 1
    @Rayon: agreed, hence my vote-to-close (hopefully pending an edit to the question to clarify what the OP wants). – David Thomas Jul 01 '16 at 18:13
  • @cody where you going to put this if condition? In order that it should execute????? – Shahbaz Hashmi Jul 01 '16 at 18:35
  • A few things: JavaScript (and therefore jQuery) generally works at a document level. So rather than using the term "my site" it might be better to think of it as "your document". An iframe element is an element within "your document" and thus is not separate from "your document". So, the question is, how do you use jQuery to listen to clicks on your document. The place to start in your quest is with [the documentation](http://api.jquery.com/click/), and researching how events work in jQuery and JavaScript, especially [the information they bring with them](http://api.jquery.com/event.target/). – Heretic Monkey Jul 01 '16 at 18:49

2 Answers2

0

You are placing two methods as conditions. I would avoid that as much as possible. Method returns can be quite tricky in javascript. Lookup the javascript truth table

https://dorey.github.io/JavaScript-Equality-Table/

Instead use more concrete returns from your methods. Something like

$("#identifier").method()(function(){
    execute code here
    return true;
});

That way when you check the result in your if statement you will know what will happen.

Lockless
  • 497
  • 1
  • 5
  • 12
0

Your question is absolutely wrong. Function call is statement. You cant put statement as condition. Except it returns something. And they are event call. So there is no right place for that if condition. It doesn't matter you are using AND or OR operator. If you want to hide something on click of html element. Do something like this.

HTML

<button id='mysite' onclick='hided()'></button>
<button id='iframe' onclick='hided()'></button>

JAVASCRIPT

function hided()
{
// hide that dialog
}           
Shahbaz Hashmi
  • 2,631
  • 2
  • 26
  • 49