I am trying to understand how these jquery code work
function findVideoForElement(el) {
var parentControls=$(el).parents('.video_controls[rel]');
if (parentControls.length==0) {
return $('video[id=]');
} else {
return $('#'+parentControls.attr('rel'));
}
}
When parents() is called ,it returns the elements matching the expression '.video_controls[rel]' .What exactly does this expression mean.Is it class="video_controls" ? I could not figure out what the [rel] part means.
Also,does $('video[id=]') mean element with id=”video” ?
What would $('#'+parentControls.attr('rel')) return?
'.video_controls[rel]'means “has the classvideo_controlsand has arelattribute defined”$('video[id=]')means “any<video>tag with anidattribute set to the empty string.$('#' + parentControls.attr('rel'))would return the element with an id equal to therelattribute on the parentControls element.For more information on jQuery selectors, you can consult their documentation.