Create an HTML element to read it’s attributes in jQuery

Hi everyone! I am working on a WordPress plugin for embedding videos, and I came across needing to read an iframe’s attributes, before it is displayed anywhere. I searched on many forums, the jQuery documentation, and eventually found that you can create an element without it actually being present in the HTML! It’s frustratingly simple:

{code type-js}
var element = $(‘‘);

alert(element.attr(‘src’)); //
alert(element.attr(‘height’)); // 315

Since $() is an object selector, you can also create the object on the spot, without it actually existing in the page! Cool, huh?