This is really slowing down my progress this morning. Any help would be incredible. Here's my code that I'm using to try to get each text box:
$('.contactInfo input[type="text"]').each(function () {
});
The above code works but it keeps grabbing select boxes as well. I've tried using a colon in between the class name and input type identifier as well as a number of other ways to get each text box (:input, :text, type=text, etc.). Forgive my styling on here as I'm completely new to asking questions and haven't gotten the hang of the formatting.
Note: .contactInfo
is a class assigned to the div that contains the text boxes I want to get. Also, I'm using the chosen jquery plugin to style my select boxes as well. This may or may not have anything to do with my issue, just wanted to let you all know.
Thanks in advance for anything you guys can help me with!
Update: I've tried every solution listed here. Each one grabs the select box, however, it doesn't return its id. So, I'm just using a workaround that checks if its id is null so that I can skip it during the iterations. I really appreciate each of you for your input! Thanks!
To get all input fields inside div with JavaScript, we select the container div with querySelector . Then we select all the input elements inside with querySelectorAll . to add inputs inside the div. to select the div with querySelector .
In JavaScript, there are some approaches to add a class to an element. We can use the . className property or the . add() method to add a class name to the particular element.
See http://api.jquery.com/text-selector/:
$('.contactInfo input:text')
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