Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get all text boxes within a given div based on its class name?

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!

like image 864
thebdawk05 Avatar asked Jun 25 '13 15:06

thebdawk05


People also ask

How do I get all input elements in a div?

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 .

How to add class to div element in JavaScript?

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.


1 Answers

See http://api.jquery.com/text-selector/:

$('.contactInfo input:text')

like image 175
nekaab Avatar answered Oct 01 '22 00:10

nekaab