Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

querySelectorAll, wildcard element match?

I am using document.querySelectorAll()

I know that [id^='id1'] will match all ids starting with id1.

[id$='textBox'] will match all ids ending with textBox.

But I want a combination of these two. This is kind of what I want to do :

document.querySelectorAll('[id should shart with id1 and ending with textBox]')

Is this possible?

like image 769
AR_Dev Avatar asked Feb 03 '17 13:02

AR_Dev


People also ask

What does the querySelectorAll () method do?

querySelectorAll() The Document method querySelectorAll() returns a static (not live) NodeList representing a list of the document's elements that match the specified group of selectors.

Does querySelectorAll return elements in order?

The querySelectorAll() methods on the Document , DocumentFragment , and Element interfaces must return a NodeList containing all of the matching Element nodes within the subtrees of the context node, in document order.

Is getElementsByClassName faster than querySelectorAll?

querySelectorAll is much faster than getElementsByTagName and getElementsByClassName when accessing a member of the collection because of the differences in how live and non-live collections are stored. But again, getElementsByTagName and getElementsByClassName are not slow.

How do I get the last element in querySelectorAll?

To get the last element with specific class name: Use the querySelectorAll() method to get a NodeList containing the elements with the specific class. Convert the NodeList to an array. Use the pop() method to get the last element of the array.


1 Answers

It's possible to combine selector by concatenating without any space.

document.querySelectorAll("[id$='textBox'][id^='id1']")
like image 144
Pranav C Balan Avatar answered Oct 21 '22 19:10

Pranav C Balan