Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jquery

dom

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

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

That is ".resumehint"

like image 361
omg Avatar asked Aug 28 '09 06:08

omg


People also ask

What is before in jQuery?

before( function ) A function that returns an HTML string, DOM element(s), text node(s), or jQuery object to insert before each element in the set of matched elements. Receives the index position of the element in the set as an argument.

How can I find previous siblings in jQuery?

jQuery prev() Method The prev() method returns the previous sibling element of the selected element. Sibling elements are elements that share the same parent. The DOM tree: This method traverse backwards along the previous sibling of DOM elements.

What is $() in jQuery?

$() = window. jQuery() $()/jQuery() is a selector function that selects DOM elements. Most of the time you will need to start with $() function. It is advisable to use jQuery after DOM is loaded fully.

How do I find a specific parent in jQuery?

jQuery parent() Method The parent() method returns the direct parent element of the selected element. The DOM tree: This method only traverse a single level up the DOM tree.


1 Answers

$(this).prev("div") 

or

$(this).prev() 

or

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

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

like image 66
Jason Avatar answered Sep 28 '22 02:09

Jason