barrypicker barrypicker - 4 months ago 14
Javascript Question

Using JQuery how to get ID of object passed into function

When using JavaScript I can create a function that takes an object as a parameter...

function doSomething(someObject) {
var id = $(object).attr("id");

Assuming I call it like...

$("#myobject").click(function (event) {

... how do I get the id? The .attr returns undefined.

I have searched for this topic and I find many examples where the id is passed to the function, not the object itself. I can't seem to find an example where the object is passed.


You never used passed argument!

var id = $(someObject).attr("id"); 

Another option could be to use as this in event-handler function refers to element on which event is invoked.