If you want to have events on html elements loaded/added dynamically,
you need to bind the event after the element has been inserted into
the page.

$("#myresult").html(html);
// define your click event here


Or  with jquery 1.3 you can use .live()
http://docs.jquery.com/Events/live



On Jan 15, 5:41 pm, Mikael <mhedeng...@gmail.com> wrote:
> Thanks Milos.
> When I fixed this coding error I get a button but I still can not get
> any click event for this button.
>
> This is how I try to get this click event:
>
>         $('.test_select').bind("click", function() {
>                 var thisName = $(this).attr('name');
>                 $('#test_list').html(thisName + " clicked");
>                 return false;
>         });
>
> On 15 Jan, 15:22, Miloš Rašić <milos.ra...@gmail.com> wrote:
>
>
>
> > Try fixing your html in the php code like this:
>
> >  echo '<input class="test_select" type="button" name="test_select_1"
> > id="test_select_1" value="Select" />';
> > You forgot to close that class property in the input.
>
> > On Thu, Jan 15, 2009 at 12:12 PM, Mikael <mhedeng...@gmail.com> wrote:
>
> > > I am new to javascript and jQuery programming so my problem might be
> > > very simple to explain but please bare with me.
>
> > > I want to make a selection in a list created by a php-file that is
> > > called from another php-file using jQuery and ajax but it fails.
> > > My example is very limited but shows the main problem.
>
> > > The first php-file has abutton defined like this:
> > >  <input class="mini_browse" type="button" value="Browse test" />
>
> > > I also have a div to show the result:
> > >  <div id="myresult">Show the result here</div>
>
> > > The jQuery entry looks like this:
> > > jQuery(document).ready(function($) {
> > >        $('.mini_browse').bind("click", function() {
> > >                $.ajax({
> > >                        type: "get", url: "test-ajax.php", data: { action:
> > > 'test' },
> > >                        error: function() {$("#myresult").html("Ajax
> > > error");},
> > >                        success: function(html){ //so, if data is 
> > > retrieved,
> > > store it in
> > > html
> > >                                $("#myresult").html(html);
> > >                        }
> > >                }); //close jQuery.ajax
> > >                return false;
> > >        });
> > > });
>
> > > When I click the button I get a call to test-ajax.php as expected and
> > > the output is displayed in the myresult div but not as expected.
>
> > > The test-ajax.php executes this:
> > >  echo '<input class="test_select type="button" name="test_select_1"
> > > id="test_select_1" value="Select" />';
>
> > > The button is not displayed as a button but like an input text with
> > > the text "Select" in it and I can not get a click event from it.
> > > I can not see the output from test-ajax.php when I view the page
> > > source so I guess that I have to get it included in the document
> > > somehow but how?
>
> > > Can anybody point me in the right direction to solve this?
>
> > > Thanks!

Reply via email to