Reputation: 11
im stack here allthe day trying to edit a value of input text using JS,
I don't know if there is another way to do this knowing that this text input doesn't have the id attribute and doesn't have the name attribute
but it is inside an element with a unique id (text-input-1 and text-input-2)
<div class="mat-form"> <text-input _ngcontent18="" formcontrolname="nom" class="ng-untouched " id="text-input-1"> <input _ngcontent29="" type="text" class="ng-touched"> </text-input> </div> <div class="mat-form"> <text-input _ngcontent18="" formcontrolname="prenom" class="ng-untouched " id="text-input-2"> <input _ngcontent29="" type="text" class="ng-touched"> </text-input> </div>
so im trying to get the element inside id="text-input-1" give him an unique id,
example
<input id="prenom_input" _ngcontent-fno-c29="" type="text" class="ng-touched">
and then change the value with
document.getElementById("nom_input").value = "Jean";
and
document.getElementById("prenom_input").value = "leclaire";
or if there is other way how to do it
Thank you everybody.
Upvotes: 0
Views: 54
Reputation: 11
because my question is related to same subjet its better to keep it in same Stackoverflow Question,
I have case that the parent element doses not have an unique id
can i get the
input element inside some how else to change the value of this input.
<mail-input placeholder="Email" class="ng-untouched"> <input autocomplete="off" type="text" class="ng-touched"> </mail-input>
Thanks everybody
Upvotes: 0
Reputation: 429
You can access the inputs using querySelector
because it is the same as CSS selectors:
// The first input
const inputNom = document.querySelector('text-input#text-input-1 input');
// The second input
const inputPrenom = document.querySelector('text-input#text-input-2 input');
// Set/get the values using JS
inputNom.value = '...';
Upvotes: 4