javascript - Select sibling before an element in Jquery? -


the dom looks this:

<body> <div>a</div> <div>b</div> <div>c</div> <div id="selected">d</div> <div>e</div> <div>f</div> <div>g</div> </body> 

now can select <div id="selected">d</div> using $("div#selected"), how can select element before it, <div>c</div>.

does have ideas this?

simplest way using prev()

$("div#selected").prev(); 

according docs, prev() will

get preceding sibling...


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -