jQuery: The Write Less, Do More JavaScript Library

simple question regarding trigger jquery events with non-jquery code

View: New views
7 Messages — Rating Filter:   Alert me  

simple question regarding trigger jquery events with non-jquery code

by jQueryNoobzor :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Alright so I'm far from a jQuery pro and this is what I'm trying to do;

I'm using Colorbox to display content in a 'lightbox'

<script type="text/javascript">
var WindowShown = 0;
$(document).ready(function(){
        $(".iframe").colorbox({innerWidth:"810px", innerHeight:"580px", iframe:true});
});
</script>

and here's my code

<p>Outside webpage (IFrame)</p>

This works excellent, the iframe content comes up within the lightbox (as defined in an external colorbox javascript file) UPON clicking the 'outside webpage (IFrame)' link.

So I'm good until there.

But, what I'm trying to do is have the iframe show up when the user moves his/her mouse outside of the viewable area. I have the code for that and it's working fine and basically at the end it has the ability to run a function e.g. 'lastchance();'

My question is, how do I tell the lastchance function to 'click' the iframe-class link?

I've tried doing it with:

document.getElementById('clickme').click();

but to no avail

I know jquery supports other events like onload, onmouseover, etc. but I need to trigger my jquery event (the lightbox) from a non-jquery piece of code.

Help!

Re: simple question regarding trigger jquery events with non-jquery code

by Michel Belleville :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Use jQuery in the first place :

document.getElementById() doesn't wrap what it finds in the jQuery result array so there's no jQuery .click() method for your result.

So use jQuery selectors like this :
$('#clickme').click();

The added bonus is they're a lot more powerful an slicker than ye old document.getElementById()

Michel Belleville


2009/11/6 jQueryNoobzor <warkorea@...>

Alright so I'm far from a jQuery pro and this is what I'm trying to do;

I'm using Colorbox to display content in a 'lightbox'

<script type="text/javascript">
var WindowShown = 0;
$(document).ready(function(){
       $(".iframe").colorbox({innerWidth:"810px", innerHeight:"580px",
iframe:true});
});
</script>

and here's my code

<p> http://www.disney.com Outside webpage (IFrame) </p>

This works excellent, the iframe content comes up within the lightbox (as
defined in an external colorbox javascript file) UPON clicking the 'outside
webpage (IFrame)' link.

So I'm good until there.

But, what I'm trying to do is have the iframe show up when the user moves
his/her mouse outside of the viewable area. I have the code for that and
it's working fine and basically at the end it has the ability to run a
function e.g. 'lastchance();'

My question is, how do I tell the lastchance function to 'click' the
iframe-class link?

I've tried doing it with:

document.getElementById('clickme').click();

but to no avail

I know jquery supports other events like onload, onmouseover, etc. but I
need to trigger my jquery event (the lightbox) from a non-jquery piece of
code.

Help!
--
View this message in context: http://old.nabble.com/simple-question-regarding-trigger-jquery-events-with-non-jquery-code-tp26230150s27240p26230150.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.



Re: simple question regarding trigger jquery events with non-jquery code

by jQueryNoobzor :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you so much for your response Michel. Being the complete noob that I am though I can't seem to implement it as desired.

The code works fine when I put it in my document ready function like;

$(document).ready(function(){
        $(".iframe").colorbox({innerWidth:"810px", innerHeight:"580px", iframe:true}, function(){WindowShown=1;});
        $('#clickme').click();
});

Ofcourse this way it loads as soon as the page loads (or before it finishes loading even).

But how do I 'trigger' the click only upon a certain event? Let's say when my other javascript calls LastChance(); ?

E.g.

$(document).ready(function(){
        $(".iframe").colorbox({innerWidth:"810px", innerHeight:"580px", iframe:true}, function(){WindowShown=1;});
});

function LastChance() { // execute the event!
        $('#clickme').click();
}


And then when my other piece of javascript triggers LastChance function it does the .click() stuff.

Do you get what I'm saying? Sorry for the noob question, I'm sure the answer is really simple.

Is there a jquery for dummies book? :D


Michel Belleville wrote:
Use jQuery in the first place :

document.getElementById() doesn't wrap what it finds in the jQuery result
array so there's no jQuery .click() method for your result.

So use jQuery selectors like this :
$('#clickme').click();

Re: simple question regarding trigger jquery events with non-jquery code

by Michel Belleville :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This second question is far from noobish, especially since what you suggest should work as you expect as far as I can see here.

As for the first question and my first answer, I merely wanted to point out that document.getElementById() is a pure dom method, jQuery-free and unable to use the nifty .click() that jQuery provides and that is guaranteed cross-browser. Sorry if I sometimes sound sarcastic, I usually don't mean it, english being my second language.

Michel Belleville


2009/11/6 jQueryNoobzor <warkorea@...>

Thank you so much for your response Michel. Being the complete noob that I am
though I can't seem to implement it as desired.

The code works fine when I put it in my document ready function like;

$(document).ready(function(){
       $(".iframe").colorbox({innerWidth:"810px", innerHeight:"580px",
iframe:true}, function(){WindowShown=1;});
       $('#clickme').click();
});

Ofcourse this way it loads as soon as the page loads (or before it finishes
loading even).

But how do I 'trigger' the click only upon a certain event? Let's say when
my other javascript calls LastChance(); ?

E.g.

$(document).ready(function(){
       $(".iframe").colorbox({innerWidth:"810px", innerHeight:"580px",
iframe:true}, function(){WindowShown=1;});
});

function LastChance() { // execute the event!
       $('#clickme').click();
}


And then when my other piece of javascript triggers LastChance function it
does the .click() stuff.

Do you get what I'm saying? Sorry for the noob question, I'm sure the answer
is really simple.

Is there a jquery for dummies book? :D



Michel Belleville wrote:
>
> Use jQuery in the first place :
>
> document.getElementById() doesn't wrap what it finds in the jQuery result
> array so there's no jQuery .click() method for your result.
>
> So use jQuery selectors like this :
> $('#clickme').click();
>

--
View this message in context: http://old.nabble.com/simple-question-regarding-trigger-jquery-events-with-non-jquery-code-tp26230150s27240p26230906.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.



Re: simple question regarding trigger jquery events with non-jquery code

by Bjarki-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm not sure if I under stand you. Are you trying to trigger the click
event inside another event ?
if so then you do it like this

$('selector').blur(function(){
    $('#clickme').click();
});
blur is just an example here you can use what ever event you like for
this.
list of events http://docs.jquery.com/Events

with regards
Bjarki Heiðar

On Nov 6, 9:42 pm, jQueryNoobzor <warko...@...> wrote:

> Thank you so much for your response Michel. Being the complete noob that I am
> though I can't seem to implement it as desired.
>
> The code works fine when I put it in my document ready function like;
>
> $(document).ready(function(){
>         $(".iframe").colorbox({innerWidth:"810px", innerHeight:"580px",
> iframe:true}, function(){WindowShown=1;});
>         $('#clickme').click();
>
> });
>
> Ofcourse this way it loads as soon as the page loads (or before it finishes
> loading even).
>
> But how do I 'trigger' the click only upon a certain event? Let's say when
> my other javascript calls LastChance(); ?
>
> E.g.
>
> $(document).ready(function(){
>         $(".iframe").colorbox({innerWidth:"810px", innerHeight:"580px",
> iframe:true}, function(){WindowShown=1;});
>
> });
>
> function LastChance() { // execute the event!
>         $('#clickme').click();
>
> }
>
> And then when my other piece of javascript triggers LastChance function it
> does the .click() stuff.
>
> Do you get what I'm saying? Sorry for the noob question, I'm sure the answer
> is really simple.
>
> Is there a jquery for dummies book? :D
>
> Michel Belleville wrote:
>
> > Use jQuery in the first place :
>
> > document.getElementById() doesn't wrap what it finds in the jQuery result
> > array so there's no jQuery .click() method for your result.
>
> > So use jQuery selectors like this :
> > $('#clickme').click();
>
> --
> View this message in context:http://old.nabble.com/simple-question-regarding-trigger-jquery-events...
> Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Re: simple question regarding trigger jquery events with non-jquery code

by jQueryNoobzor :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you but the problem is that it's not an event detectable by jquery as far as I know. It's an event that I have a script for and it triggers when the mouse moves towards a tab or the close window, but NOT when it moves to the left, right or bottom of the browser's viewable area.

So I just need to 'execute' a jquery event ( the .click) from a non-jquery piece of code.

Sorry for making it sound complicated :(


Bjarki-2 wrote:
I'm not sure if I under stand you. Are you trying to trigger the click
event inside another event ?
if so then you do it like this

$('selector').blur(function(){
    $('#clickme').click();
});
blur is just an example here you can use what ever event you like for
this.
list of events http://docs.jquery.com/Events

with regards
Bjarki Heiðar

On Nov 6, 9:42 pm, jQueryNoobzor <warko...@gmail.com> wrote:
> Thank you so much for your response Michel. Being the complete noob that I am
> though I can't seem to implement it as desired.
>
> The code works fine when I put it in my document ready function like;
>
> $(document).ready(function(){
>         $(".iframe").colorbox({innerWidth:"810px", innerHeight:"580px",
> iframe:true}, function(){WindowShown=1;});
>         $('#clickme').click();
>
> });
>
> Ofcourse this way it loads as soon as the page loads (or before it finishes
> loading even).
>
> But how do I 'trigger' the click only upon a certain event? Let's say when
> my other javascript calls LastChance(); ?
>
> E.g.
>
> $(document).ready(function(){
>         $(".iframe").colorbox({innerWidth:"810px", innerHeight:"580px",
> iframe:true}, function(){WindowShown=1;});
>
> });
>
> function LastChance() { // execute the event!
>         $('#clickme').click();
>
> }
>
> And then when my other piece of javascript triggers LastChance function it
> does the .click() stuff.
>
> Do you get what I'm saying? Sorry for the noob question, I'm sure the answer
> is really simple.
>
> Is there a jquery for dummies book? :D
>
> Michel Belleville wrote:
>
> > Use jQuery in the first place :
>
> > document.getElementById() doesn't wrap what it finds in the jQuery result
> > array so there's no jQuery .click() method for your result.
>
> > So use jQuery selectors like this :
> > $('#clickme').click();
>
> --
> View this message in context:http://old.nabble.com/simple-question-regarding-trigger-jquery-events...
> Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Re: simple question regarding trigger jquery events with non-jquery code

by Michel Belleville :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm not sure I get what you need but if you need to use jQuery from another script you can as long as you're placing that other script after you've loaded jQuery. Then again, of course, this other script should give you an opportunity to run the callback somewhere. As long as jQuery() is declared in the same context there should be no problem.

Michel Belleville


2009/11/8 jQueryNoobzor <warkorea@...>

Thank you but the problem is that it's not an event detectable by jquery as
far as I know. It's an event that I have a script for and it triggers when
the mouse moves towards a tab or the close window, but NOT when it moves to
the left, right or bottom of the browser's viewable area.

So I just need to 'execute' a jquery event ( the .click) from a non-jquery
piece of code.

Sorry for making it sound complicated :(



Bjarki-2 wrote:
>
> I'm not sure if I under stand you. Are you trying to trigger the click
> event inside another event ?
> if so then you do it like this
>
> $('selector').blur(function(){
>     $('#clickme').click();
> });
> blur is just an example here you can use what ever event you like for
> this.
> list of events http://docs.jquery.com/Events
>
> with regards
> Bjarki Heiðar
>
> On Nov 6, 9:42 pm, jQueryNoobzor <warko...@...> wrote:
>> Thank you so much for your response Michel. Being the complete noob that
>> I am
>> though I can't seem to implement it as desired.
>>
>> The code works fine when I put it in my document ready function like;
>>
>> $(document).ready(function(){
>>         $(".iframe").colorbox({innerWidth:"810px", innerHeight:"580px",
>> iframe:true}, function(){WindowShown=1;});
>>         $('#clickme').click();
>>
>> });
>>
>> Ofcourse this way it loads as soon as the page loads (or before it
>> finishes
>> loading even).
>>
>> But how do I 'trigger' the click only upon a certain event? Let's say
>> when
>> my other javascript calls LastChance(); ?
>>
>> E.g.
>>
>> $(document).ready(function(){
>>         $(".iframe").colorbox({innerWidth:"810px", innerHeight:"580px",
>> iframe:true}, function(){WindowShown=1;});
>>
>> });
>>
>> function LastChance() { // execute the event!
>>         $('#clickme').click();
>>
>> }
>>
>> And then when my other piece of javascript triggers LastChance function
>> it
>> does the .click() stuff.
>>
>> Do you get what I'm saying? Sorry for the noob question, I'm sure the
>> answer
>> is really simple.
>>
>> Is there a jquery for dummies book? :D
>>
>> Michel Belleville wrote:
>>
>> > Use jQuery in the first place :
>>
>> > document.getElementById() doesn't wrap what it finds in the jQuery
>> result
>> > array so there's no jQuery .click() method for your result.
>>
>> > So use jQuery selectors like this :
>> > $('#clickme').click();
>>
>> --
>> View this message in
>> context:http://old.nabble.com/simple-question-regarding-trigger-jquery-events...
>> Sent from the jQuery General Discussion mailing list archive at
>> Nabble.com.
>
>

--
View this message in context: http://old.nabble.com/simple-question-regarding-trigger-jquery-events-with-non-jquery-code-tp26230150s27240p26251933.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.