omg
omg

Reputation: 139862

How to find the div before a specified element with jQuery?

<td>
    <div class="resumehint"></div>
    <input type="file" id="resume" />
</td>

How to get the div before "#resume" with jQuery?

That is ".resumehint"

Upvotes: 32

Views: 58340

Answers (4)

Ashish Yadav
Ashish Yadav

Reputation: 3196

for multiple elements:

$('#resume').prevAll()

Upvotes: 5

Christian C. Salvad&#243;
Christian C. Salvad&#243;

Reputation: 827316

Use the Traversing/prev function:

$('#resume').prev('div');

And if you know the CSS class of the div to be more specific:

$('#resume').prev('div.resumehint');

Upvotes: 5

rahul
rahul

Reputation: 187030

$("#resume").prev();

Upvotes: 1

Jason
Jason

Reputation: 52523

$(this).prev("div")

or

$(this).prev()

or

$(this).prev(".resumehint")

you can replace $(this) with $('#resume') if you are outside a function.

Upvotes: 55

Related Questions