tags:

views:

69

answers:

3

Hi,

I am using JQuery for my application.. Having a doubt on how to add a id to my element tr.

My code is

    <script type="text/javascript">
      $(document).ready(function(){
               var tr = document.createElement('tr');
              var td1=document.createElement('td');  
               tr.appendChild(td);    
 });
 </script>

I am trying to add an id to the tr element

like

EDIT : by $(tr).attr('id', 'entryRow'+increment); And resolved..Thanks

+3  A: 

You don't have to use pure JavaScript to create elements, jQuery has a handy interface for that too. try:

$("<tr id='newId'><td></td></tr>")

See also: http://docs.jquery.com/Core/jQuery#htmlownerDocument

Kobi
+2  A: 

Since tr is not a jQuery object, you will have to write as below:

$(tr).attr('id', 'NewIdValue');

If you have more than one attributes to be set, you can write as below (using Json Notation):

$(tr).attr( {
 id: 'newIdValue',
 name: 'newName'  
  } );
Technowise
+2  A: 

If you have even more data to associate with one row, you could use data structore to store that data:

$(tr).data('key', anything);
var any = $(tr).data('key');
gregor
That is true, although not really related to the question...
Kobi
well, neither is your answer ...
gregor