Hi Kazurayam,
I’m feeling really stupid right now but I can’t seem to get my head around this selector…
What I tried:
// these are the 3 elements using the same ID:
document.querySelectorAll('#discretionaryPopupButton ')
NodeList(3) [button#discretionaryPopupButton.btn.btn-default.k-button,
button#discretionaryPopupButton.btn.btn-default.k-button,
button#discretionaryPopupButton.btn.btn-default.k-button]
0:button#discretionaryPopupButton.btn.btn-default.k-button
1:button#discretionaryPopupButton.btn.btn-default.k-button
2:button#discretionaryPopupButton.btn.btn-default.k-button
length: 3
[[Prototype]]: NodeList
When I try to apply the nth-child selector I do not get the output I expected:
document.querySelector('#discretionaryPopupButton :nth-child(1)')
null
document.querySelector('#discretionaryPopupButton button:nth-child(1)')
null
Thats is when I realised I should use the container:
document.querySelector('#discretionaryPopupButtonContainer :nth-child(1)')
<button type="button" id="discretionaryPopupButton" class="btn btn-default k-button" data-bind="text: buttonText, click: openPopup, visible: useButton">Dossiergegevens aanpassen</button>
OR with the extra ‘button’ tag:
document.querySelector('#discretionaryPopupButtonContainer button:nth-child(1)')
<button type="button" id="discretionaryPopupButton" class="btn btn-default k-button" data-bind="text: buttonText, click: openPopup, visible: useButton">Dossiergegevens aanpassen</button>
→ Now I can select the 1st element (of the 3 elements with the same ID)
Next step is to select the 2nd element, so I tried:
document.querySelector('#discretionaryPopupButtonContainer :nth-child(2)')
<a id="discretionaryPopupLink" data-bind="text: buttonText, click: openPopup, invisible: useButton" style="display: none;">Dossiergegevens aanpassen</a>
_____
document.querySelector('#discretionaryPopupButtonContainer button:nth-child(2)')
null
No matter what I try I either get the wrong element or I am unable to select the second button.
Could you please point me in the right direction?