Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #29398
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Give alert if form checkbox array is empty |
| Date | 2016-01-22 00:07 +0100 |
| Organization | PointedEars Software (PES) |
| Message-ID | <1667727.3LLY7Eaobt@PointedEars.de> (permalink) |
| References | (3 earlier) <405a9$569fab1d$11450e97$16733@nntpswitch.blueworldhosting.com> <3964788.uURLdzOTfL@PointedEars.de> <19572$56a08e96$520da86c$20767@nntpswitch.blueworldhosting.com> <2757422.ibQTPl4PXH@PointedEars.de> <a5d87$56a0b254$11450e97$21447@nntpswitch.blueworldhosting.com> |
Cezary Tomczyk wrote:
> On 21/01/2016 09:52, Thomas 'PointedEars' Lahn wrote:
>> […] The *support* of document.querySelector() does _not_ imply support$
>> of certain *selectors* *because* certain selectors were not yet
>> specified/supported when document.querySelector() was introduced. For
>> example, the “:checked” pseudo class was standardized with CSS3 Selectors
>> in 2011 [1]; document.querySelector() was standardized with Selectors API
>> Level 1 in2013 [2].
>>
>> [1] <https://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked>
>> [2] <https://www.w3.org/TR/2013/REC-selectors-api-20130221/>
>
> Got it.
It was a bad example, though, because specification-wise “:checked”
*predates* querySelector() (qS) and querySelectorAll() (qSA). On the other
hand it shows the chronological disparity between the support of either
feature. That is, “:checked” *might* be safe with qS() and qSA() – and a
comparison on <http://caniuse.com/> suggests it is [1]¹ – because it became
a standard before d.qS(), but you can think of more recently
introduced/supported selectors to which this does not apply because of that.
<https://www.w3.org/TR/2013/WD-selectors4-20130502/#overview> where the
“Level” is “4” only, are prime candidates.
> Can you recommend some reliable way of test if specified selector is
> supported or not?
Perhaps. (Wrong question ;-))
(But: Good question, in this case.) There might be a reliable way. It is
specified both in Selectors API Level 1 (which refers to CSS Selectors Level
3) and DOM Level 4 (which refers to CSS Selectors Level 4 [WD/ED]) that for
an “*invalid*” selector a DOMException with the “code” attribute set to
DOMException::SYNTAX_ERR (12) should be thrown by qS() and qSA():
<https://www.w3.org/TR/2013/REC-selectors-api-20130221/#processing-selectors>
<https://www.w3.org/TR/2015/REC-dom-20151119/#scope-match-a-selectors-string>
This is implemented so in Blink 537.26 (tested in Chromium 46.0.2490.71 on
Debian GNU/Linux) and Gecko 38.0 (Iceweasel 38.1.0), i.e. a DOMException is
thrown whose “code” property has the value 12.
Blink:
| > try { document.querySelector(":blub") } catch (e) { console.log(e,
| > e.code) }
| DOMException: Failed to execute 'querySelector' on 'Document': ':blub' is
| not a valid selector.(…) 12
Gecko:
| < try { document.querySelector(":blub") } catch (e) { e }
| > […] DOMException [SyntaxError: "An invalid or illegal string was
| > specified"
| code: 12
| nsresult: 0x8053000c
| location: debugger eval code:1]
Therefore, the following works there:
try
{
document.querySelector(":blub");
}
catch (e)
{
if (e instanceof DOMException && e.code === 12) // ²
{
/* handling for invalid/unsupported selector */
}
}
This can be confirmed for specified but unsupported selectors in that Gecko
version with ":read-write" and in that Blink version with ":drop(…)".
________
¹ Something can be learned here: In a compatibility matrix, it can be
useful to provide functionality to compare the support for *several*
features in one view. caniuse.com does not provide such yet, so
I had to open several tabs and switch between them.
² They should have standardized Mozilla’s “… catch (e if …) { … }”
so that you can have “… catch (e if e instanceof DOMException) { … }”
as a shortcut everywhere.
[1] <http://caniuse.com/#search=querySelector>
<http://caniuse.com/#search=%3Achecked>
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Give alert if form checkbox array is empty Bunyip <bunyip@koalanet.com.au> - 2016-01-20 13:28 +1000
Re: Give alert if form checkbox array is empty JJ <jj4public@vfemail.net> - 2016-01-20 12:30 +0700
Re: Give alert if form checkbox array is empty Bunyip <bunyip@koalanet.com.au> - 2016-01-20 17:55 +1000
Re: Give alert if form checkbox array is empty JJ <jj4public@vfemail.net> - 2016-01-20 19:29 +0700
Re: Give alert if form checkbox array is empty "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-01-20 13:46 +0100
Re: Give alert if form checkbox array is empty Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2016-01-20 08:23 +0000
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-20 15:52 +0100
Re: Give alert if form checkbox array is empty Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2016-01-20 15:43 +0000
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-20 17:15 +0100
Re: Give alert if form checkbox array is empty Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2016-01-20 17:53 +0000
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-20 20:39 +0100
Re: Give alert if form checkbox array is empty Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2016-01-20 22:46 +0000
Re: Give alert if form checkbox array is empty Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2016-01-21 07:53 +0000
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-21 10:52 +0100
Re: Give alert if form checkbox array is empty Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2016-01-21 10:26 +0000
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-22 00:07 +0100
Re: Give alert if form checkbox array is empty Stefan Weiss <krewecherl@gmail.com> - 2016-01-20 10:28 +0100
Re: Give alert if form checkbox array is empty Bunyip <bunyip@koalanet.com.au> - 2016-01-21 08:05 +1000
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-21 00:59 +0100
Re: Give alert if form checkbox array is empty Stefan Weiss <krewecherl@gmail.com> - 2016-01-21 03:17 +0100
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-21 08:54 +0100
Re: Give alert if form checkbox array is empty Stefan Weiss <krewecherl@gmail.com> - 2016-01-21 12:17 +0100
Re: Give alert if form checkbox array is empty John Harris <niam@jghnorth.org.uk.invalid> - 2016-01-21 14:16 +0000
Re: Give alert if form checkbox array is empty Scott Sauyet <scott.sauyet@gmail.com> - 2016-01-21 19:52 -0800
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-22 09:48 +0100
Re: Give alert if form checkbox array is empty Scott Sauyet <scott.sauyet@gmail.com> - 2016-01-22 10:45 -0800
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-23 19:41 +0100
Re: Give alert if form checkbox array is empty Scott Sauyet <scott.sauyet@gmail.com> - 2016-01-24 17:51 -0800
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-25 19:46 +0100
Re: Give alert if form checkbox array is empty Scott Sauyet <scott.sauyet@gmail.com> - 2016-01-27 11:09 -0800
Re: Give alert if form checkbox array is empty Dr J R Stockton <reply1600@merlyn.demon.co.uk.invalid> - 2016-01-23 22:22 +0000
Re: Give alert if form checkbox array is empty Scott Sauyet <scott.sauyet@gmail.com> - 2016-01-27 11:06 -0800
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-28 14:46 +0100
Re: Give alert if form checkbox array is empty Gene Wirchenko <genew@telus.net> - 2016-01-28 10:30 -0800
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-28 20:06 +0100
Re: Give alert if form checkbox array is empty Scott Sauyet <scott.sauyet@gmail.com> - 2016-01-28 23:32 -0800
Re: Give alert if form checkbox array is empty "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-01-29 09:05 +0100
Re: Give alert if form checkbox array is empty Scott Sauyet <scott.sauyet@gmail.com> - 2016-01-29 06:02 -0800
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-29 20:54 +0100
Re: Give alert if form checkbox array is empty John Harris <niam@jghnorth.org.uk.invalid> - 2016-01-29 10:36 +0000
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-02-09 04:39 +0100
Re: Give alert if form checkbox array is empty John Harris <niam@jghnorth.org.uk.invalid> - 2016-02-09 18:07 +0000
Re: Give alert if form checkbox array is empty Gene Wirchenko <genew@telus.net> - 2016-01-29 09:32 -0800
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-29 20:34 +0100
Re: Give alert if form checkbox array is empty Aleksandro <aleksandro@gmx.com> - 2016-01-29 16:50 -0300
Re: Give alert if form checkbox array is empty Stefan Weiss <krewecherl@gmail.com> - 2016-01-30 03:31 +0100
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-30 04:19 +0100
Re: Give alert if form checkbox array is empty Stefan Weiss <krewecherl@gmail.com> - 2016-01-30 05:01 +0100
Re: Give alert if form checkbox array is empty Aleksandro <aleksandro@gmx.com> - 2016-01-28 16:39 -0300
Re: Give alert if form checkbox array is empty Scott Sauyet <scott.sauyet@gmail.com> - 2016-01-29 06:04 -0800
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-29 20:54 +0100
Re: Give alert if form checkbox array is empty Scott Sauyet <scott.sauyet@gmail.com> - 2016-01-29 14:55 -0800
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-30 04:55 +0100
Re: Give alert if form checkbox array is empty Scott Sauyet <scott.sauyet@gmail.com> - 2016-01-30 15:48 -0800
Re: Give alert if form checkbox array is empty Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-31 21:02 +0100
Re: Give alert if form checkbox array is empty Scott Sauyet <scott.sauyet@gmail.com> - 2016-01-31 13:08 -0800
Re: Give alert if form checkbox array is empty Andrew Poulos <ap_prog@hotmail.com> - 2016-02-01 12:28 +1100
Re: Give alert if form checkbox array is empty Scott Sauyet <scott.sauyet@gmail.com> - 2016-02-01 17:58 -0800
Re: Give alert if form checkbox array is empty "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-01-20 06:25 -0800
Re: Give alert if form checkbox array is empty Aleksandro <aleksandro@gmx.com> - 2016-01-20 12:54 -0300
csiph-web