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)










share|improve this question



























    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)










    share|improve this question

























      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)










      share|improve this question















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 14:49









      halfer

      14.2k757104




      14.2k757104










      asked Jan 28 '10 at 14:49









      shin

      12.2k51152220




      12.2k51152220






















          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();
          ...
          );





          share|improve this answer




















          • that was it. Thanks.
            – shin
            Jan 28 '10 at 15:07

















          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");
          );





          share|improve this answer






















          • It still does not alert. It executes php.
            – shin
            Jan 28 '10 at 14:56

















          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.






          share|improve this answer




















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            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

























            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();
            ...
            );





            share|improve this answer




















            • that was it. Thanks.
              – shin
              Jan 28 '10 at 15:07














            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();
            ...
            );





            share|improve this answer




















            • that was it. Thanks.
              – shin
              Jan 28 '10 at 15:07












            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();
            ...
            );





            share|improve this answer












            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();
            ...
            );






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 28 '10 at 15:06









            Kevin Gorski

            3,42911713




            3,42911713











            • 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




            that was it. Thanks.
            – shin
            Jan 28 '10 at 15:07












            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");
            );





            share|improve this answer






















            • It still does not alert. It executes php.
              – shin
              Jan 28 '10 at 14:56














            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");
            );





            share|improve this answer






















            • It still does not alert. It executes php.
              – shin
              Jan 28 '10 at 14:56












            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");
            );





            share|improve this answer














            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");
            );






            share|improve this answer














            share|improve this answer



            share|improve this answer








            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
















            • 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










            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.






            share|improve this answer
























              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.






              share|improve this answer






















                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.






                share|improve this answer












                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 28 '10 at 14:55









                John Hoven

                3,58522229




                3,58522229



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Top Tejano songwriter Luis Silva dead of heart attack at 64

                    ReactJS Fetched API data displays live - need Data displayed static

                    Evgeni Malkin