tags:

views:

38

answers:

1

I need to access two attributes I've assigned to my row in code-behind.

userId and eventId

here is what I have.. and have tried.

function ExportToPbuse() 
{
    var rowCount = GeneralReport.rows.length;
    for (var i = 0; i < rowCount; i++) {
        var userId= GeneralTbl.tbodies.row[i]$(this).attr("userid")
        var eventId= GeneralTbl.tbodies.row[i]$(this).attr("eventid")
        //exportArray add userId and eventId
    }
}

this doesn't work... and I've tried a few other ways, but I'm really not all that familiar with jquery so any suggestions would help greatly..thanks :)

+3  A: 

In jQuery, $ is an ordinary function (but with an unusual name) that can take a selector or a DOM element.

Therefore, you can write $(GeneralTbl.tbodies.row[i]).attr("userid"). (Assuming that GeneralTbl.tbodies.row[i] is a <tr> DOM element)

SLaks
I've never seen a selector like $(GeneralTbl.tbodies.row[i]) - I didn't realize you could put plain JS in the selector like that.
neatlysliced
Thank you so much!! works :)
Avien
@neatlysliced: It isn't a selector - it's a regular DOM element. `$(this)` in an event handler is exactly the same. http://api.jquery.com/jQuery/
SLaks
@SLaks I always had it in my head as a selector - $("body"), but now I see I can do $(document.body)... never realized that. Thanks! +1... it would be interesting to run performance comparisons.
neatlysliced