Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I want to get input value without id

In this code, I want to get input value by javascript, How can I do?
Thanks.

<div id='my-id' class='my-class'>
    <div>
        <input type='text'>
    </div>
</div>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Easiest way is querySelector

document.querySelector("#my-id input")

Old way is getElementsByTagName

document.getElementsByTagName("input")[0];
document.getElementById("my-id").getElementsByTagName("input")[0];

If your element is in a form, you can go old school with

document.forms[0].elements[0]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading