HighDots Forums  

simple question regarding trigger jquery events withnon-jquery code

jQuery jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.


Discuss simple question regarding trigger jquery events withnon-jquery code in the jQuery forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jQueryNoobzor
 
Posts: n/a

Default simple question regarding trigger jquery events withnon-jquery code - 11-06-2009 , 06:05 AM






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.

Reply With Quote
  #2  
Old   
Michel Belleville
 
Posts: n/a

Default Re: [jQuery] simple question regarding trigger jquery events withnon-jquery code - 11-06-2009 , 06:29 AM






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 (AT) gmail (DOT) com>

Quote:
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.


Reply With Quote
  #3  
Old   
jQueryNoobzor
 
Posts: n/a

Default Re: [jQuery] simple question regarding trigger jquery events withnon-jquery code - 11-06-2009 , 04:42 PM



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?



Michel Belleville wrote:
Quote:
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.

Reply With Quote
  #4  
Old   
Michel Belleville
 
Posts: n/a

Default Re: [jQuery] simple question regarding trigger jquery events withnon-jquery code - 11-06-2009 , 07:12 PM



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 (AT) gmail (DOT) com>

Quote:
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?



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.


Reply With Quote
  #5  
Old   
Bjarki
 
Posts: n/a

Default Re: simple question regarding trigger jquery events withnon-jquery code - 11-06-2009 , 08:27 PM



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... (AT) gmail (DOT) com> wrote:
Quote:
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?

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.

Reply With Quote
  #6  
Old   
jQueryNoobzor
 
Posts: n/a

Default Re: [jQuery] simple question regarding trigger jquery events withnon-jquery code - 11-08-2009 , 04:13 AM



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:
Quote:
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... (AT) gmail (DOT) 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?

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.

Reply With Quote
  #7  
Old   
Michel Belleville
 
Posts: n/a

Default Re: [jQuery] simple question regarding trigger jquery events withnon-jquery code - 11-08-2009 , 02:23 PM



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 (AT) gmail (DOT) com>

Quote:
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... (AT) gmail (DOT) 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?

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.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.