Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple condition selector in jQuery

Tags:

jquery

I have the following code, and I want to select the element with type = text and id of 'announcement_date'. How would I do this in jQuery? Note that both the elements have same id. This is in a legacy classic ASP page I am working with.

<input type="hidden" name="announcement_date" id="announcement_date" value="1111"></input>
<input type="text" name="announcement_date" id="announcement_date" value="323"></input>
<input type="text" name="eff_date" id="eff_date" value="123"></input>
<input type="text" name="end_date" id="end_date" value="123"></input>

I tried the selector below, but it fails to select the correct element.

$("#announcement_date type=text").addClass("error");
like image 246
Sunil Avatar asked Dec 13 '22 00:12

Sunil


1 Answers

IDs have to be unique.

(if for some reason you cannot change the html) you can select by name though as

$('input[name="announcement_date"][type="text"]');
like image 78
Gabriele Petrioli Avatar answered Jan 17 '23 15:01

Gabriele Petrioli