Created
June 4, 2017 15:24
-
-
Save winsoor/a63fbbeba437902f2a8af3427e64e0d2 to your computer and use it in GitHub Desktop.
Функции на JavaScript заменяющие jquery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* источник: 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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* источник: 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