64 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
While ``++:<element_type>++`` and ``++[type="<element_type>"]++`` can both be used in jQuery to select elements by their type, ``++[type="<element_type>"]++`` is far faster because it can take advantage of the native DOM ``++querySelectorAll()++`` method in modern browsers.
This rule raises an issue when following selectors are used:
* ``++:checkbox++``
* ``++:file++``
* ``++:image++``
* ``++:password++``
* ``++:radio++``
* ``++:reset++``
* ``++:text++``
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
var input = $( "form input:radio" ); // Noncompliant
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
var input = $( "form input[type=radio]" ); // Compliant
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Use the "[type='{0}']" selector here instead of ":{0}".
'''
== Comments And Links
(visible only on this page)
=== on 30 Apr 2015, 07:21:35 Ann Campbell wrote:
https://api.jquery.com/radio-selector/
=== on 30 Apr 2015, 07:57:05 Linda Martin wrote:
Reviewed!
=== on 6 May 2015, 08:29:55 Elena Vilchik wrote:
\[~ann.campbell.2] The same rule applies to 6 more selectors, so I updated rule accordingly. Could you verify it?
=== on 6 May 2015, 11:43:30 Ann Campbell wrote:
looks fine to me [~elena.vilchik]
=== on 1 Nov 2019, 17:30:35 Elena Vilchik wrote:
See \https://github.com/SonarSource/SonarJS/issues/1698
endif::env-github,rspecator-view[]