8 examples of 'get element by attribute javascript' in JavaScript

Every line of 'get element by attribute javascript' 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
37function getElementWithAttribute(attribute)
38{
39 var allElements = document.getElementsByTagName('*');
40 for (var i = 0, n = allElements.length; i < n; i++)
41 if (allElements[i].getAttribute(attribute) !== null)
42 return allElements[i];
43 return null;
44}
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

228function getElementByAttributeValue(attribName, value)
229{
230 return getDocumentElementByAttributeValue(document, attribName, value);
231}
124function getByAttr(tag, attr, value) {
125 return document.querySelector(tag + '[' + attr + '="' + value + '"]');
126}
16export function getElement(el: FinderResult): ElementFinder {
17 return typeof el === 'string' ? element(by.css(el)) : el;
18}
29function getValue(selector) {
30 return browser.executeScript(`
31 return $('${selector}').val();
32 `);
33}
47getAttribute(name) {
48 if (name == "style") {
49 return this.root.getAttribute("style");
50 }
51 return this[ATTRIBUTE_SYMBOL][name]
52}
99function valueFromElement(el) {
100 switch(el.getAttribute('type')) {
101 case 'radio':
102 return el.checked ? el.value : null
103 case 'checkbox':
104 return 'data', el.checked
105 }
106 return el.value
107}
42getAttribute (name) {
43 return this[ATTRIBUTE_SYMBOL][name]
44}

Related snippets