What you are looking for is event delegation.
In your last version, you are attaching a click event handler to
every a you add to your table. It can be time and resource
consuming.
A better way is to bind the click event to the container where you
will load your dynamic content and wait for the
Hi Greg,
I'm defined an ID to my table (ID = tb) that have my report, and
trying to code like this:
$(#tb a).click(function() {
alert('Test');
});
But it doesnt working.
In other words, how can I define that all a in my table triggers an
event when clicked?
Tks
On Nov 18, 7:25 am, Denis Caggiano denisribe...@gmail.com wrote:
I'm defined an ID to my table (ID = tb) that have my report, and
trying to code like this:
$(#tb a).click(function() {
alert('Test');
});
#tb a points to link elements that are the direct children of the
The hint of the day:
*The other thing to make sure you're doing is to call your code once*
*the DOM is loaded*
*---By Scott*
**
Im using AJAX and defyning the $(#tb a).click before the DOM is loaded and
that was the problem.
Here is my $.post now:
$.post(
'adm_cobranca_ajax.asp',
{ mes:
Have you tried simply doing:
$(#tb a).click(function() {
alert('Test');
});
Depending on the table's code will break your heart...
Wil
On Wed, Nov 18, 2009 at 4:25 AM, Denis Caggiano denisribe...@gmail.comwrote:
Hi Greg,
I'm defined an ID to my table (ID = tb) that have my report,
Now Im get confused...
Wil, Is the code that you suggested equal that I wrote?
Mine
$(#tb a).click(function() {
alert(this.id);
});
Wil
$(#tb a).click(function() {
alert('Test');
});
Tks
You are kind of defeating the purpose of Jquery if you put the call to
the function in an A element. Does the parent of the A element in
question have an ID? You could then call $('parent a'). If there is
more than one A in there you can target it with other selectors
function thisismyfunction(){
}
$(document).ready(function(){
code in here
});
$(document).ready(function(){
thisismyfunction()
});
On Jun 9, 6:40 am, simon si...@uvfx.tv wrote:
I have some code seperated by script:
$(document).ready(function(){
code in here
so I would put my function outside of the $(document).ready(function()
{ }?
Many thanks
Si
yes
On Jun 9, 9:20 am, simon si...@uvfx.tv wrote:
so I would put my function outside of the $(document).ready(function()
{ }?
Many thanks
Si
thanks for that, the only thing i did not try, I am learning now :-)
many thanks
Si
Thanks. I ready an article somewhere and it mentioned not combining
old coding forms with new in reference to jQuery. It didn't make
much sense to me and this confirms it. I'll continue to code with
functions and such and just supplement with jQuery where beneficial.
Thanks
On Dec 4, 6:36
On Tue, Dec 9, 2008 at 10:12 AM, Will [EMAIL PROTECTED] wrote:
Thanks. I ready an article somewhere and it mentioned not combining
old coding forms with new in reference to jQuery. It didn't make
much sense to me and this confirms it. I'll continue to code with
functions and such and just
Sorry...this question is a little ambiguous to me. Can you be more
specific or give an example/use case? I think you will have to hard
code every event, because otherwise there's no logic dictating what
happens when, say, you click something. As for defining actual
functions and reusable
jQuery isn't a separate language with its own rules. It's still JavaScript
code, just like any other JavaScript code. Functions, variables, reusable
code, those are all good practice, and none of it changes because you're
using jQuery.
Could you give a specific example of some jQuery code that
Erik Beeson wrote:
The value from $.get CAN NOT be returned from isTracked because isTracked will
have returned before the $.get callback executes.
Shame :/ But thank you for that answer. I was fighting because I
thought that it is possible. Waste of time :/
So I have no choice and put all
$.get is asynchronous, meaning the call to $.get returns immediately, even
before the callback has happened. To answer your specific question, setting
a variable who's scope is outside the callback is as easy as defining the
variable outside the callback:
var foo;
$.get(..., function() { foo =
Erik Beeson wrote:
$.get is asynchronous, meaning the call to $.get returns immediately,
even before the callback has happened. To answer your specific
question, setting a variable who's scope is outside the callback is as
easy as defining the variable outside the callback:
Erik - your
function isTracked(personcode, callback) {
$.get('trackstudent/istracked.php', {'personcode': personcode}, callback);
}
isTracked(code, function(tracked) {
// do something with tracked, exactly as you would have done above.
});
I thought that I understand that but Im doing something
First of all - Thank You very much - it is good lesson.
To answer your specific question, setting
a variable who's scope is outside the callback is as easy as defining the
variable outside the callback:
var foo;
$.get(..., function() { foo = ...; });
I tried that before:
function test()
with Firebug enabled, and watch
the console to see the order of execution.
-Mike
-Original Message-
From: jquery-en@googlegroups.com
[mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED]
Sent: Thursday, September 27, 2007 7:01 AM
To: jQuery (English)
Subject: [jQuery] Re: functions
To answer your specific question, setting
a variable who's scope is outside the callback is as easy as defining the
variable outside the callback:
var foo;
$.get(..., function() { foo = ...; });
Ahh, I know know where was my mistake.
I tried something like that:
function a() {
var ret;
Michael Geary wrote:
You're still expecting things to happen in the wrong order. It's *inside the
callback* that the data becomes available, and this is
long after isTracked() returns. Try this instead:
Yes, but I want have a function that will return what i get from
istracked.php
to use it
Michael Geary wrote:
You're still expecting things to happen in the wrong order.
It's *inside the callback* that the data becomes available,
and this is long after isTracked() returns.
From: [EMAIL PROTECTED]
Yes, but I want have a function that will return what i get from
From: MrNase
I have the function called init() where I use Ajax.get to
fetch the list and I have several other functions but writing
them down like:
$(document).ready(function() {
init();
otherfunction(); // booth need the data provided by init();
function();
});
25 matches
Mail list logo