10 examples of 'getelementbyclass' in JavaScript

Every line of 'getelementbyclass' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
17function getParentByClass(el, className) {
18 do {
19 if (el.classList.contains(className)) {
20 return el;
21 } else {
22 el = el.parentNode;
23 }
24 } while (el && el.parentNode)
25}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

580Video.prototype.getElementByClass = function getElementByClass(className) {
581 return this.element.getElementsByClassName(className)[0];
582};
57export function findElementParentByClassName(element, className, includeSelf) {
58 let el;
59 if (includeSelf === false) {
60 el = element.parentElement;
61 } else {
62 /** @type {HTMLElement} */
63 el = (element);
64 }
65 while (el != null && !el.classList.contains(className)) {
66 el = el.parentElement;
67 }
68 return el;
69}
31function hasClass(element, clazz) {
32 return (` ${element.className} `).indexOf(` ${clazz} `) > -1;
33}
394value: function findAncestorByClass(el, className) {
395 while ((el = el.parentElement) && !el.classList.contains(className)) {
396 ;
397 }
398
399 return el;
400}
81function findParent(inEl: Element, className: string): ?Element {
82 var el = inEl; // this is for Flow.
83 do {
84 if (el.classList.contains(className)) return el;
85 el = el.parentElement;
86 } while (el);
87 return null;
88}
45function JQueryClosestByClass(element, clazz) {
46 while (element) {
47 if (JQueryHasClass(element, clazz)) {
48 return element;
49 }
50 element = element.parentNode;
51 }
52 return null;
53}
154function addClass(element_id, classname) {
155 document.getElementById(element_id).className += (" " + classname);
156}
12export function queryElementsByClass(
13 selectors: string,
14 parentNode = document
15): any {
16 return parentNode.getElementsByClassName(selectors);
17}
2296function addClassName(element, className) {
2297 if (!(element = $(element))) return;
2298
2299 if (!hasClassName(element, className))
2300 element.className += (element.className ? ' ' : '') + className;
2301
2302 return element;
2303}

Related snippets