Alex Rivera | Logout

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

Asked 2009-08-28T06:34:53.407
32
<td>
    <div class="resumehint"></div>
    <input type="file" id="resume" />
</td>

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

That is ".resumehint"

Edit
Report

2 Answers

56
$(this).prev("div")

or

$(this).prev()

or

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

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

answered 2009-08-28T06:37:25.073
5

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');
answered 2009-08-28T06:39:54.817

Your Answer