After adding elements to the DOM, I usually have to add the livequery plugin
and modify
my code ( if I'm using jQuery versions prior to 1.3.  I think as of 1.3,
there's a function
called .live() that does what livequery did in prior versions.)  So, if your
jquery version
is prior to 1.3, you'd add the livequery plugin and code such as:

$("#table td").livequery("click", function(){
               alert("jhgjgh");
});

If you're using jquery 1.3 or later, check out the .live() function on the
jquery site.

hth,

Rick


On Mon, May 25, 2009 at 2:43 AM, Literide <alexey-cherka...@yandex.ru>wrote:

>
> Hi
> I'm new to jQuery.
> I'm writing some code to show a picture if user clicks on table row.
> this is the table
> <table id="restable" border="0">
> <thead><tr>
> <th class="cat" width="150"><a href="">Category</a></th>
> <th class="brand" width="150"><a href="">Brand</a></th>
> <th class="name" width="300"><a href="">Name</a></th>
> <th class="weight" width="50"><a href="">Weight</a></th>
> </tr></thead>
> <tbody id="table">
> </tbody>
> </table>
>
> The table is filled with this function
> function search(sortt,dirt) {
> $.getJSON("/jsonsearch.php", {cat: $("select#catselect").val(), brand:
> $("select#brandselect").val(), name: $("input#search").val(), sort:
> sortt, dir: dirt}, function(j){
>      $("tbody#table").empty();
>      var row='';
>      for (var i = 0; i < j.length; i++) {
>        row="<tr><td width='150'>"+j[i].cats+"</td><td width='150'>"+j
> [i].brand+"</td><td class='name' width='300'>"+j[i].name+"</td><td
> width='50'>"+j[i].weight+"</td></tr>";
>        $("#restable tbody").append(row);
>      }
>    })
>
> This is the function i put inside $(document).ready()
> $("#table td").click(function(){
>                alert("jhgjgh");
> });
>
> The problem is that click event doesn't fire.
>
> One more related question
> If i get it working, how do i get the contents of the row that user
> clicked. I need Name from that row.
>
> Thank you.
>
>


-- 
--------------------------------------------------------------------------------------------------------------------------------------------------
"Ninety percent of the politicians give the other ten percent a bad
reputation."  Henry Kissinger

Reply via email to