Huma Ali
Huma Ali

Reputation: 1809

How to select two elements inside a div in jquery

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

Answers (4)

efrat v
efrat v

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

Ashish Saini
Ashish Saini

Reputation: 308

This worked for me

var val1 = document.getElementsByTagName("input")[4];
var val2 = document.getElementsByTagName("input")[5];
$([val2, val1]).keyup(() => { }

Upvotes: -1

guradio
guradio

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>

  1. add comma
  2. if there is no comma it will look for child

Upvotes: 1

Adil
Adil

Reputation: 148110

You can use Multiple Selector (“selector1, selector2, selectorN”)

$(".footer-contact input[type=text], .footer-contact textarea").each(function(){
    this.value = "";
});

Upvotes: 2

Related Questions