Why does JS code “var a = document.querySelector(‘a[data-a=1]’);” cause error?

From the selectors specification: Attribute values must be CSS identifiers or strings. Identifiers cannot start with a number. Strings must be quoted. 1 is therefore neither a valid identifier nor a string. Use “1” (which is a string) instead. var a = document.querySelector(‘a[data-a=”1″]’);

How to use querySelectorAll only for elements that have a specific attribute set?

You can use querySelectorAll() like this: var test = document.querySelectorAll(‘input[value][type=”checkbox”]:not([value=””])’); This translates to: get all inputs with the attribute “value” and has the attribute “value” that is not blank. In this demo, it disables the checkbox with a non-blank value.

Javascript .querySelector find by innerTEXT

OP’s question is about plain JavaScript and not jQuery. Although there are plenty of answers and I like @Pawan Nogariya answer, please check this alternative out. You can use XPATH in JavaScript. More info on the MDN article here. The document.evaluate() method evaluates an XPATH query/expression. So you can pass XPATH expressions there, traverse into … Read more

querySelector, wildcard element match?

[id^=’someId’] will match all ids starting with someId. [id$=’someId’] will match all ids ending with someId. [id*=’someId’] will match all ids containing someId. If you’re looking for the name attribute just substitute id with name. If you’re talking about the tag name of the element I don’t believe there is a way using querySelector

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)