Reputation: 1809
I have a div with class footer-contact
and inside that div, I have several input
and textarea
elements. I want to empty their text. I tried using the following selector but it doesn't work. What am I doing wrong?
$(".footer-contact input[type=text] textarea").val('');
Upvotes: 2
Views: 3197
Reputation: 1
First you select the container, and then you can search inside of it. You need to separate with commmas:
$(".footer-contact").find("input[type=text], textarea").val('');
Upvotes: 0
Reputation: 308
This worked for me
var val1 = document.getElementsByTagName("input")[4];
var val2 = document.getElementsByTagName("input")[5];
$([val2, val1]).keyup(() => { }
Upvotes: -1
Reputation: 15555
$(".footer-contact,input[type=text],textarea").val('');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='text' class='footer-contact' value='asdas'>
<input type='text' value='asdas'>
<textarea>asdas</textarea>
Upvotes: 1
Reputation: 148110
You can use Multiple Selector (“selector1, selector2, selectorN”)
$(".footer-contact input[type=text], .footer-contact textarea").each(function(){
this.value = "";
});
Upvotes: 2