Reputation:
How to get all values of input type text with a specific class?
I tried this code. But it's not showing the expected answer.
$('input .classname').each(function(){
console.log($(this).val());
});
Upvotes: 2
Views: 41466
Reputation: 491
This should select all input fields of type text with the class "classname".
$('input[type="text"].classname').each(function () {
console.log($(this).val());
});
Upvotes: 8
Reputation: 3603
i think keyup
is what you are looking for
$('.classname').keyup(function() {
console.log($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<input type='text' class='classname'>
Upvotes: 0
Reputation: 919
One way is to assign a class for all your input
elements, that way it will not interfere with unwanted input
elements.
For example when you don't need to get all the input
elements in the DOM
$('.test').each(function(){
console.log($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class='test' value='wanted data'/>
<input value='unwanted data'/>
Upvotes: 3