Mick
Mick

Reputation: 2898

Jquery <tr> and id elements

Hi I am new to Jquery and wondered if I can give a an ID and if so how can I then get the value back . The best I have come up with so for is

  rid = $('tr').attr('id').val() 

but no luck ......

thanks

Upvotes: 0

Views: 659

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039200

To set the value:

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

To get the value:

var id = $('tr').attr('id');

Upvotes: 1

Nick Craver
Nick Craver

Reputation: 630569

No need for the .val(), just use this:

var rid = $('tr').attr('id'); 

.attr('attributeName') returns a string (in most cases) of the attribute, .val() is for getting the value from input type elements (<input>, <select>, <textarea>, etc).

Upvotes: 3

Related Questions