9 examples of 'onclick add class' in JavaScript

Every line of 'onclick add class' 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
23public add(...classNames: string[]): void {
24 const attr = this.ownerElement.getAttribute('class');
25 const list = attr ? attr.split(' ') : [];
26 for (const className of classNames) {
27 if (!list.includes(className)) {
28 list.push(className);
29 }
30 }
31 this.ownerElement.setAttribute('class', list.join(' '));
32}
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

18function addClass(className) {
19 this.classList.add(className);
20
21 return this;
22}
230function addClass(name)
231{
232 var c = new Class(name);
233 classes.push(c);
234
235 var option = document.createElement('option');
236 option.text = name;
237 var list = document.getElementById('classList');
238 list.add(option, list.length - 1);
239
240 return c;
241}
348export function add__class(el, class_name) {
349 return el.classList.add(class_name)
350}
105export function add_class(o, cn) {
106 if (!has_class(o, cn))
107 o.className += " " + cn;
108}
8export default function addClass (el, ...classNames) {
9 el.classList.add(...classNames)
10}
19export function addClass(el, c) {
20 c != null && el[classList].add(c);
21}
352function addClass(el, c) {
353 c != null && el[classList].add(c);
354}
57function addClass (tag, className) {
58 tag.classList.add(className)
59}

Related snippets