I select several HTMLElements and perform actions on them, in this case I assign a new class (CSS). All this, of course, is implemented in jQuery, but you need to do it yourself.
function $() { var elements = []; for (var i = 0; i < arguments.length; i++) { var element = arguments[i]; if (typeof element == "string") element = document.getElementById(element); if (typeof element == "array") elements.concat(element); elements.push(element); } elements.addClass = addClass; return elements; } function addClass(classStr) { for (i in this) { var classArray = i.className.split(" "); if (!inArray(classArray)) { classArray.push(classStr); this[i].className = classArray.join(" "); } } } function inArray(arr, value) { var i; for (i=0; i < arr.length; i++) { if (arr[i] === value) { return true; } } return false; } $("string1").addClass("underline");
Does not work, because $ ("string1") does not return values. But how then to implement this? So that all the arguments to the $ () function are assigned a class value?