I want to alert all the ID that contains the class failed after pushing a button or a command.
Use class selector to get elements with particular class. You can use each() to traverse all the element. Bind the click event to button, you can use button id in id selector to bind the event.
Html
<input id="first" class="failed" />
<input id="last" class="failed" />
<input id="city" class="failed" />
<input id="state" class="failed" />
<input type="button" id="btn" value="click" />
Javascript
$('#btn').click(function () {
$('.failed').each(function () {
alert(this.id);
});
});