How to execute another action after generated by ajax with jQuery?
up vote
0
down vote
favorite
I have this ajax function with jquery. (http://pastie.org/798788)
The outputs is the following.
<div class="content">
<h1>Latest Messages or Task To Do</h1>
<ul style="display: block;" id="message_ul">
<li class="86">
<div class="listbox"><span class="user">
<strong>Administrator</strong></span>
<span class="date">2010-01-28 08:57:43</span>
<a href="http://127.0.0.1/ci_backendpro2/index.php/messages/admin/changestatus/86"
class="todo">to do</a>
<span class="msg">Change links in message, to do, completed
and delete to anchor </span>
</div>
</li>
<li class="85">
<div class="listbox"><span class="user">
<strong>Administrator</strong></span>
<span class="date">2010-01-28 08:51:15</span>
<a href="http://127.0.0.1/ci_backendpro2/index.php/messages/admin/changestatus/85"
class="todo">to do</a>
<span class="msg"> meta tag keywords and
description should show from page input/database </span>
</div>
</li>
<li class="84">
...
...
Now I am trying to add another ajax with class="todo". However when I tried this for testing. It does not alert. It executes the php function.
$(".todo").click(function()
event.preventDefault();
alert("hei");
);
I am not sure why. Is it because it is created by ajax?
Is it something to do with binding? How can I make it work?
I am using CodeIgniter.
Other php functions are here. (http://pastie.org/798802)
jquery ajax
add a comment |
up vote
0
down vote
favorite
I have this ajax function with jquery. (http://pastie.org/798788)
The outputs is the following.
<div class="content">
<h1>Latest Messages or Task To Do</h1>
<ul style="display: block;" id="message_ul">
<li class="86">
<div class="listbox"><span class="user">
<strong>Administrator</strong></span>
<span class="date">2010-01-28 08:57:43</span>
<a href="http://127.0.0.1/ci_backendpro2/index.php/messages/admin/changestatus/86"
class="todo">to do</a>
<span class="msg">Change links in message, to do, completed
and delete to anchor </span>
</div>
</li>
<li class="85">
<div class="listbox"><span class="user">
<strong>Administrator</strong></span>
<span class="date">2010-01-28 08:51:15</span>
<a href="http://127.0.0.1/ci_backendpro2/index.php/messages/admin/changestatus/85"
class="todo">to do</a>
<span class="msg"> meta tag keywords and
description should show from page input/database </span>
</div>
</li>
<li class="84">
...
...
Now I am trying to add another ajax with class="todo". However when I tried this for testing. It does not alert. It executes the php function.
$(".todo").click(function()
event.preventDefault();
alert("hei");
);
I am not sure why. Is it because it is created by ajax?
Is it something to do with binding? How can I make it work?
I am using CodeIgniter.
Other php functions are here. (http://pastie.org/798802)
jquery ajax
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have this ajax function with jquery. (http://pastie.org/798788)
The outputs is the following.
<div class="content">
<h1>Latest Messages or Task To Do</h1>
<ul style="display: block;" id="message_ul">
<li class="86">
<div class="listbox"><span class="user">
<strong>Administrator</strong></span>
<span class="date">2010-01-28 08:57:43</span>
<a href="http://127.0.0.1/ci_backendpro2/index.php/messages/admin/changestatus/86"
class="todo">to do</a>
<span class="msg">Change links in message, to do, completed
and delete to anchor </span>
</div>
</li>
<li class="85">
<div class="listbox"><span class="user">
<strong>Administrator</strong></span>
<span class="date">2010-01-28 08:51:15</span>
<a href="http://127.0.0.1/ci_backendpro2/index.php/messages/admin/changestatus/85"
class="todo">to do</a>
<span class="msg"> meta tag keywords and
description should show from page input/database </span>
</div>
</li>
<li class="84">
...
...
Now I am trying to add another ajax with class="todo". However when I tried this for testing. It does not alert. It executes the php function.
$(".todo").click(function()
event.preventDefault();
alert("hei");
);
I am not sure why. Is it because it is created by ajax?
Is it something to do with binding? How can I make it work?
I am using CodeIgniter.
Other php functions are here. (http://pastie.org/798802)
jquery ajax
I have this ajax function with jquery. (http://pastie.org/798788)
The outputs is the following.
<div class="content">
<h1>Latest Messages or Task To Do</h1>
<ul style="display: block;" id="message_ul">
<li class="86">
<div class="listbox"><span class="user">
<strong>Administrator</strong></span>
<span class="date">2010-01-28 08:57:43</span>
<a href="http://127.0.0.1/ci_backendpro2/index.php/messages/admin/changestatus/86"
class="todo">to do</a>
<span class="msg">Change links in message, to do, completed
and delete to anchor </span>
</div>
</li>
<li class="85">
<div class="listbox"><span class="user">
<strong>Administrator</strong></span>
<span class="date">2010-01-28 08:51:15</span>
<a href="http://127.0.0.1/ci_backendpro2/index.php/messages/admin/changestatus/85"
class="todo">to do</a>
<span class="msg"> meta tag keywords and
description should show from page input/database </span>
</div>
</li>
<li class="84">
...
...
Now I am trying to add another ajax with class="todo". However when I tried this for testing. It does not alert. It executes the php function.
$(".todo").click(function()
event.preventDefault();
alert("hei");
);
I am not sure why. Is it because it is created by ajax?
Is it something to do with binding? How can I make it work?
I am using CodeIgniter.
Other php functions are here. (http://pastie.org/798802)
jquery ajax
jquery ajax
edited Nov 10 at 14:49
halfer
14.2k757104
14.2k757104
asked Jan 28 '10 at 14:49
shin
12.2k51152220
12.2k51152220
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
It looks like you need to be using the live-style event binding and name the event object as a parameter to the click handler.
$(".todo").live('click', function(event)
event.preventDefault();
...
);
that was it. Thanks.
– shin
Jan 28 '10 at 15:07
add a comment |
up vote
1
down vote
You'll need to use a live event:
$(".todo").live('click', function() // <- Extend the "click" event to every .todo element created in the future
event.preventDefault();
alert("hei");
);
It still does not alert. It executes php.
– shin
Jan 28 '10 at 14:56
add a comment |
up vote
0
down vote
Not sure I entirely understand how everything is going on. But if you're inserting the links with class 'todo' after you've executed the 'bind' function, you either need to:
a) Re-call the bind function (first unbinding).
b) Use the jquery live function so you automatically attach to any new 'todo' classes.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
It looks like you need to be using the live-style event binding and name the event object as a parameter to the click handler.
$(".todo").live('click', function(event)
event.preventDefault();
...
);
that was it. Thanks.
– shin
Jan 28 '10 at 15:07
add a comment |
up vote
2
down vote
accepted
It looks like you need to be using the live-style event binding and name the event object as a parameter to the click handler.
$(".todo").live('click', function(event)
event.preventDefault();
...
);
that was it. Thanks.
– shin
Jan 28 '10 at 15:07
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
It looks like you need to be using the live-style event binding and name the event object as a parameter to the click handler.
$(".todo").live('click', function(event)
event.preventDefault();
...
);
It looks like you need to be using the live-style event binding and name the event object as a parameter to the click handler.
$(".todo").live('click', function(event)
event.preventDefault();
...
);
answered Jan 28 '10 at 15:06
Kevin Gorski
3,42911713
3,42911713
that was it. Thanks.
– shin
Jan 28 '10 at 15:07
add a comment |
that was it. Thanks.
– shin
Jan 28 '10 at 15:07
that was it. Thanks.
– shin
Jan 28 '10 at 15:07
that was it. Thanks.
– shin
Jan 28 '10 at 15:07
add a comment |
up vote
1
down vote
You'll need to use a live event:
$(".todo").live('click', function() // <- Extend the "click" event to every .todo element created in the future
event.preventDefault();
alert("hei");
);
It still does not alert. It executes php.
– shin
Jan 28 '10 at 14:56
add a comment |
up vote
1
down vote
You'll need to use a live event:
$(".todo").live('click', function() // <- Extend the "click" event to every .todo element created in the future
event.preventDefault();
alert("hei");
);
It still does not alert. It executes php.
– shin
Jan 28 '10 at 14:56
add a comment |
up vote
1
down vote
up vote
1
down vote
You'll need to use a live event:
$(".todo").live('click', function() // <- Extend the "click" event to every .todo element created in the future
event.preventDefault();
alert("hei");
);
You'll need to use a live event:
$(".todo").live('click', function() // <- Extend the "click" event to every .todo element created in the future
event.preventDefault();
alert("hei");
);
edited Jan 28 '10 at 15:00
answered Jan 28 '10 at 14:53
Thiago Belem
5,93423562
5,93423562
It still does not alert. It executes php.
– shin
Jan 28 '10 at 14:56
add a comment |
It still does not alert. It executes php.
– shin
Jan 28 '10 at 14:56
It still does not alert. It executes php.
– shin
Jan 28 '10 at 14:56
It still does not alert. It executes php.
– shin
Jan 28 '10 at 14:56
add a comment |
up vote
0
down vote
Not sure I entirely understand how everything is going on. But if you're inserting the links with class 'todo' after you've executed the 'bind' function, you either need to:
a) Re-call the bind function (first unbinding).
b) Use the jquery live function so you automatically attach to any new 'todo' classes.
add a comment |
up vote
0
down vote
Not sure I entirely understand how everything is going on. But if you're inserting the links with class 'todo' after you've executed the 'bind' function, you either need to:
a) Re-call the bind function (first unbinding).
b) Use the jquery live function so you automatically attach to any new 'todo' classes.
add a comment |
up vote
0
down vote
up vote
0
down vote
Not sure I entirely understand how everything is going on. But if you're inserting the links with class 'todo' after you've executed the 'bind' function, you either need to:
a) Re-call the bind function (first unbinding).
b) Use the jquery live function so you automatically attach to any new 'todo' classes.
Not sure I entirely understand how everything is going on. But if you're inserting the links with class 'todo' after you've executed the 'bind' function, you either need to:
a) Re-call the bind function (first unbinding).
b) Use the jquery live function so you automatically attach to any new 'todo' classes.
answered Jan 28 '10 at 14:55
John Hoven
3,58522229
3,58522229
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f2155298%2fhow-to-execute-another-action-after-generated-by-ajax-with-jquery%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown