10 examples of 'jquery add attribute' in JavaScript

Every line of 'jquery add attribute' 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
22function addAttribute(attribute, value) {
23 var attributes = filterUrl.getQueryVar(attribute);
24 if (!attributes) {
25 attributes = value;
26 } else {
27 if (attributes.indexOf(value) == -1) {
28 attributes += ',' + value;
29 }
30 }
31 filterUrl = filterUrl.addQueryVar(attribute, attributes);
32 return filterUrl;
33}
504export function applyAttribute(element, name, value) {
505 if (booleanAttributes[name]) {
506 // Boolean attribute
507 if (typeof value === "string") {
508 element.setAttribute(name, "");
509 } else if (value === null) {
510 element.removeAttribute(name);
511 }
512 } else {
513 // Regular string-valued attribute
514 if (value != null) {
515 element.setAttribute(name, value.toString());
516 } else {
517 element.removeAttribute(name);
518 }
519 }
520}
96function attr(element, name) {
97 return element.getAttribute(name);
98}
90function attr(target:HTMLElement, attrName:string, attrValue:string): void {
91 target.setAttribute(attrName, attrValue);
92}
2365function writeAttribute(element, name, value) {
2366 element = $(element);
2367 var attributes = {}, table = ATTRIBUTE_TRANSLATIONS.write;
2368
2369 if (typeof name === 'object') {
2370 attributes = name;
2371 } else {
2372 attributes[name] = Object.isUndefined(value) ? true : value;
2373 }
2374
2375 for (var attr in attributes) {
2376 name = table.names[attr] || attr;
2377 value = attributes[attr];
2378 if (table.values[attr])
2379 name = table.values[attr](element, value);
2380 if (value === false || value === null)
2381 element.removeAttribute(name);
2382 else if (value === true)
2383 element.setAttribute(name, name);
2384 else element.setAttribute(name, value);
2385 }
2386
2387 return element;
2388}
2export function setAttribute(obj, key, value) {
3 getData(obj)[key] = value;
4}
206function attr(elm, attrName, val) {
207 if (typeof val == 'undefined') {
208 if (tracking.isIe) {
209 try {
210 return elm.getAttribute(attrName, 2)
211 } catch (e) {}
212 }
213 return elm.getAttribute(attrName);
214 }
215 elm.setAttribute(attrName, val);
216}
123export function setAttribute( elm, name, value ) {
124 if ( elm ) {
125 elm.setAttribute( name, value );
126 }
127}
25export function setAttribute(el: Element, name: string, value: any) {
26 if (value == null) {
27 el.removeAttribute(name)
28 } else {
29 el.setAttribute(name, value)
30 }
31}
111export function setAttr (el: ASTNode, name: string, value: string) {
112 const attr = findAttr(el, name);
113
114 if (attr) {
115 attr.value = value;
116
117 return value;
118 }
119
120 const parsedAttrName = parseAttrName(name);
121 const newAttr = { name: parsedAttrName.name, value: value, namespace: void 0 };
122
123 if (parsedAttrName.prefix && NAMESPACE_PREFIX_MAP[parsedAttrName.prefix])
124 newAttr.namespace = NAMESPACE_PREFIX_MAP[parsedAttrName.prefix];
125
126 el.attrs.push(newAttr);
127
128 return value;
129}

Related snippets