So you’ve learned a bit of JavaScript, and have learned that, for instance, on anchor tags, you can access attribute values directly:
var anchor = document.getElementById('someAnchor');
//anchor.id
// anchor.href
// anchor.title
// .etc
The only problem is that this doesn’t seem to work when you reference the DOM elements with jQuery, right? Well of course not.
// Fails
var id = $('#someAnchor').id;
So, should you need to access the href attribute (or any other native property or method for that matter), you have a handful of options.
// OPTION 1 - Use jQuery
var id = $('#someAnchor').attr('id');
// OPTION 2 - Access the DOM element
var id = $('#someAnchor')[0].id;
// OPTION 3 - Use jQuery's get method
var id = $('#someAnchor').get(0).id;
// OPTION 3b - Don't pass an index to get
anchorsArray = $('.someAnchors').get();
var thirdId = anchorsArray[2].id;
