Posts

Showing posts with the label custom-data-attribute

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

Image
Clash Royale CLAN TAG #URR8PPP Why does JS code “var a = document.querySelector('a[data-a=1]');” cause error? I've an element in the DOM: <a href="#" data-a="1">Link</a> <a href="#" data-a="1">Link</a> I want to get this element via its HTML5 custom data attribute data-a . So I write JS codes: data-a var a = document.querySelector('a[data-a=1]'); var a = document.querySelector('a[data-a=1]'); But this code doesn't work and I get an error in browser's console. (I tested Chrome and Firefox.) JS code var a = document.querySelector('a[data-a=a]'); doesn't cause error. So I think the problem is that HTML5's JS API document.querySelector doesn't support to look for the number value in HTML5 custom data attribute. var a = document.querySelector('a[data-a=a]'); document.querySelector Is this a problem of browser implementation bug or a problem of HTML5's spec re...