I was wondering if anyone knew why jQuery doesn’t have a simple $().id() method. It seems silly to have to pull the id using $().attr('id'). I would think that the id attribute was common and useful enough to have its own call.
I was wondering if anyone knew why jQuery doesn’t have a simple $().id() method.
Share
Another problem is the jQuery returns a matched set, so typically you could have more than one id. By implementing an Id function, you could be breaking chainability by returning the id of the first item in a set.
You could simply use $(‘selector’).get(0).id;