Skip to content

Instantly share code, notes, and snippets.

@winsoor
Created June 4, 2017 15:24
Show Gist options
  • Save winsoor/a63fbbeba437902f2a8af3427e64e0d2 to your computer and use it in GitHub Desktop.
Save winsoor/a63fbbeba437902f2a8af3427e64e0d2 to your computer and use it in GitHub Desktop.
Функции на JavaScript заменяющие jquery
/* источник: http://javascript.ru/unsorted/top-10-functions */
function addEvent(elem, evType, fn) {
if (elem.addEventListener) {
elem.addEventListener(evType, fn, false);
}
else if (elem.attachEvent) {
elem.attachEvent('on' + evType, fn)
}
else {
elem['on' + evType] = fn
}
}
/* источник: http://javascript.ru/unsorted/top-10-functions */
function addClass(o, c){
var re = new RegExp("(^|\\s)" + c + "(\\s|$)", "g")
if (re.test(o.className)) return
o.className = (o.className + " " + c).replace(/\s+/g, " ").replace(/(^ | $)/g, "")
}
function removeClass(o, c){
var re = new RegExp("(^|\\s)" + c + "(\\s|$)", "g")
o.className = o.className.replace(re, "$1").replace(/\s+/g, " ").replace(/(^ | $)/g, "")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment