Code javascript

Vanilla JavaScript - Wildcard (*) Selector

visibility 2,249 comment 0 access_time 10 months ago language English
<script type="text/javascript">
let selector = '[name*="password"]';
var elements = document.querySelectorAll(selector);
if(elements)
{
   elements.forEach(el=>{console.log(el.name);});
}
</script>
Loading...
copyright This page is subject to Site terms.
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

fork_right
more_vert

Code description

In vanilla JavaScript, we can use wildcard (*) to match multiple elements (nodes) in the HTML DOM object. We can also match elements with attribute starting with, ending with or contains certain values.

For example, the following selectors will 

  • [name^="password"] will match all elements with name starting with password.
  • [name$="password"] will match all elements with name ending with password.
  • [name*="password"] will match all elements with name containing password.