10 examples of 'jquery get all elements with data attribute name' in JavaScript

Every line of 'jquery get all elements with data attribute name' 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
59function getDataAttribute(element, name) {
60 if ('dataset' in element) {
61 return element.dataset[name];
62 } else {
63 return element.getAttribute('data-' + hyphenize(name));
64 }
65}
275function getDataAttribute( element, attribute ) {
276 if ( supportsDataset ) {
277 return element.dataset[attribute];
278 }
279 else {
280 return element.getAttribute( 'data-' + attribute );
281 }
282}
195function data(el, prop, value) {
196 var prefix = 'data';
197 var elData = el[prefix] || {};
198 if (typeof value === 'undefined') {
199 if (el[prefix] && el[prefix][prop]) {
200 return el[prefix][prop];
201 } else {
202 var dataAttr = el.getAttribute(prefix + '-' + prop);
203 if (typeof dataAttr !== 'undefined') {
204 return dataAttr;
205 }
206 return null;
207 }
208 } else {
209 elData[prop] = value;
210 el[prefix] = elData;
211 return el;
212 }
213}
491getData(el, name: string): string { return this.getAttribute(el, 'data-' + name); }
96function attr(element, name) {
97 return element.getAttribute(name);
98}
41public getElementDataAttributeKeyValue(element: Cheerio, { name, key }: DataAttribute): string | null {
42 const value = this.$(element).data(name)
43
44 if (name !== undefined && key !== undefined ) {
45 try {
46 return value[key]
47 } catch (e) {
48 return null
49 }
50 }
51
52 return value
53}
44function dataAttr( el, attr ) {
45 var data = el.getAttribute( 'data-' + attr );
46
47 try { // JSON.parse可能报错
48
49 // 当data===null表示,没有此属性
50 data = data === null ? undefined : data === 'true' ? true :
51 data === 'false' ? false : data === 'null' ? null :
52
53 // 如果是数字类型,则将字符串类型转成数字类型
54 +data + '' === data ? +data :
55 /(?:\{[\s\S]*\}|\[[\s\S]*\])$/.test( data ) ?
56 JSON.parse( data ) : data;
57 } catch ( ex ) {
58 data = undefined;
59 }
60
61 return data;
62}
434export function getAttribute(el, attribute) {
435 return el.getAttribute(attribute);
436}
239function extractValue ($, attribute) {
240 if ($ && $.length) {
241 return $.attr(attribute) || undefined
242 }
243 return undefined
244}
105export function getAttr (el, name: string) {
106 const attr = findAttr(el, name);
107
108 return attr ? attr.value : null;
109}

Related snippets