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?
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.
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.
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.
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.
It's possible to combine selector by concatenating without any space.
document.querySelectorAll("[id$='textBox'][id^='id1']")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With