I believe its a timing issue. jQuery might be trying to select the
table elements before javascript has finished building the table. You
might want to try wrapping the table building code in a function, then
return the jquery selector code. That way you know the table is
actually appended to the DOM when jquery runs.

$(document).ready(function(){
  createTable();
});

function createTable() {
  //your table code here...

  return function(){
    $('tbody tr:odd').addClass('odd');
    $('tbody tr:even').addClass('even');
  };
}


Give that a whirl and see what happens.

Brian

On Jun 16, 2:32 am, vile <[EMAIL PROTECTED]> wrote:
> hi can anyone help solve this problem..
>
> i created a table using javascript. basically it creates dynamic
> row...
> How come that jquery doest affect the table using  $('tr:even') and
> $('tr:odd')?
>
> heres my code
> javascript:
>     var newPara = document.getElementById('newText');
>     var mybody = document.getElementsByTagName("body")[0];
>     var newtable = document.createElement('table');
>     newtable.setAttribute('align','center');
>     newtable.setAttribute('id','clientTable');
>     var newtbody = document.createElement('tbody');
>
>     for(var i = 0; i < options.length ; i++){
>                     //create table row cols
>
>                     var tablerow = document.createElement("tr");
>                     //tablerow.setAttribute('id','tableRow');
>                     var tableLabel = document.createElement("td");
>                     var tableOpen = document.createElement("td");
>                     var tableDel = document.createElement("td");
>                     var tableSave =
> document.createElement("td");
>
>                     var newText = document.createTextNode("chat with
> guest: "+ (i + 1) +"
> ");
>                     var chatlink = document.createElement('a');
>                     var savelink = document.createElement('a');
>                     var dellink = document.createElement('a');
>
>                     //var tableObj =  document.createElement(table)
>                     var xmlfile = options[i].firstChild.data;
>                     xmlfile.substring(1,10)
>
>                     chatlink.setAttribute('href','/chat/chat_frame/'+
> xmlfile.substring(0,10));
>                     chatlink.setAttribute('target','_blank');
>                     chatlink.innerHTML = "Open Chat!"
>
>                     savelink.setAttribute('href','saveChat/' +
> options[i].firstChild.data);
>                     savelink.innerHTML = "Save";
>
>                     dellink.setAttribute('href','delXML/' +
> options[i].firstChild.data);
>                     dellink.innerHTML = "Delete";
>
>                     //contrct table
>                     tableLabel.appendChild(newText);
>                     tableOpen.appendChild(chatlink);
>                     tableSave.appendChild(savelink);
>                     tableDel.appendChild(dellink);
>
>                     tablerow.appendChild(tableLabel);
>                     tablerow.appendChild(tableOpen);
>                     tablerow.appendChild(tableSave);
>                     tablerow.appendChild(tableDel);
>                     //newtable.appendChild(tablerow);
>                     newtbody.appendChild(tablerow);
>                 }
>                 newtable.appendChild(newtbody);
>                 newPara.appendChild(newtable);
>
> jquery code:
> $(document).ready(
>
>     $('tbody tr:odd').addClass('odd');
>     $('tbody tr:even').addClass('even');
>     }
> );
>
> it works if i create a tble manually..

Reply via email to