Reputation: 304
I know that for multple classes I can look for $(".form-group.text-center") my question is how can I find an input element that is inside of the conjuction of these 2 classes
<div class="form-group text-center">
<label class="label-text no-padding"></label>
<input class="bg-color form-control mfa" placeholder="Answer" type="TEXT">
</div>
Upvotes: 1
Views: 58
Reputation: 72269
You can do:-
$(".form-group.text-center input")
Demo example:-
$(document).ready(function(){
$(".form-group.text-center input").on('mouseout',function(){
alert($(this).val());
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group text-center">
<label class="label-text no-padding"></label>
<input class="bg-color form-control mfa" placeholder="Answer" type="TEXT">
</div>
Note:- based on yout HTML structure you can go for these options also:-
$(".form-group.text-center .mfa")
$(".form-group.text-center input[type='text']")
$(".form-group.text-center input[type=text]")
Upvotes: 1
Reputation: 494
You can use $(".form-group.text-center > input")
like below:
$(document).ready(function(){
$(".form-group.text-center > input").on('mouseout',function(){
input = $(this);// $(this) means your selected object -the input-
input.val("i am an input !!");
alert(input.val());
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group text-center">
<label class="label-text no-padding"></label>
<input class="bg-color form-control mfa" placeholder="Answer" type="TEXT">
</div>
the >
means the direct child
Upvotes: 1
Reputation: 4366
Use find()
method:
$(".form-group.text-center").find("input").addClass("border")
.border{
border: 2px solid green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="form-group text-center">
<label class="label-text no-padding"></label>
<input class="bg-color form-control mfa" placeholder="Answer" type="TEXT">
</div>
Upvotes: 1