1

Hi i have a hidden div which inside hold other divs

Example

<div style="display:none">
    <div id="o-1">...<div>
    <div>...<div>
    <div>...<div>
    <div id="o-2">...<div>
    <div>...<div>
    <div>...<div>
    <div id="o-3">...<div>
    <div>...<div>
    <div>...<div>
   </div>

I am trying to get the prevAll of div id="o-3" which id starts whith o- In the above example the prevAll of o-3 are o-2 and o-1

The problem is that because the wrapper div is hidden i can get the preAll

Any suggestions are welcome

Ram
  • 143,282
  • 16
  • 168
  • 197
ntan
  • 2,195
  • 7
  • 35
  • 56

3 Answers3

3

The problem is not that the parent is set to be hidden, the element is still in your DOM.

Instead, one problem is that your HTML is a bit messed up. You aren't closing your <div> elements properly.

From your code:

<div>...<div>

Should be:

<div>...</div>

You could then use this to get the previous siblings that has an id that starts with o-:

$("#o-3").prevAll("[id^='o-']")

Live example

Christofer Eliasson
  • 32,939
  • 7
  • 74
  • 103
  • +1 for testing code, but the problem wan not the html code even if i wrote it wrong (i created a dummy code and mess it up with copy-paste).Thanks for your reply i was helpful (trigger my mind) – ntan Feb 16 '13 at 10:51
2

I don't seem to have any problems selecting hidden elements.

http://jsfiddle.net/U2YPB/2/

$.each($("#ho3").prevAll(),function(idx,div) {
    log($(div).attr("id"));
});
turiyag
  • 2,757
  • 2
  • 22
  • 21
1

Try with this

$('div:third').prevAll(':hidden');

or you can directly user

$("#o-3").prevAll("div[id^='o-']");
GautamD31
  • 28,552
  • 10
  • 64
  • 85