Sandeep Polavarapu
Sandeep Polavarapu

Reputation: 382

Jquery finding firrt element of specific class

I am using jquery to find a first element having a class "error" applied to it using the below code

$('#mainDiv input.error:eq(0)')

But the above one working only for input elements only. How to make this one to work for both input and select elements?

Upvotes: 0

Views: 761

Answers (1)

silent
silent

Reputation: 3923

$('#mainDiv .error:eq(0)')

or

$('input.error, select.error', '#mainDiv').first()

if you want to find only input and select objects

Upvotes: 3

Related Questions