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.
Why clutter up the namespace with superflous functions? You already said attr()
can do the same thing in only a few extra characters. For every extra function, it adds bytes to the file size, and time to the JavaScript parser.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With