If the user selects an option in a dropdown box, there must be added a label and a textbox. Using appendChild
, these elements get added to the end of the container
.
var newFreeformLabel = document.createElement('label'); newFreeformLabel.innerHTML = 'Omschrijving:'; var newFreeformField = document.createElement('input'); newFreeformField.className = 'textfield'; newFreeformField.name = 'factuur_orderregel[]'; var newFreeformSpacer = document.createElement('div'); newFreeformSpacer.className = 'spacer'; container.appendChild(newFreeformLabel); container.appendChild(newFreeformField); container.appendChild(newFreeformSpacer);
The issue is that these elements should be inserted at the beginning of container
, not at the end.
Is there a solution to this in PrototypeJS?
As well as appendChild
, DOM nodes have an insertBefore method
container.insertBefore(newFreeformLabel, container.firstChild);
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