Currently the code below returns an array of visible parent/sibling div's with the class .one-third
, but I need to find the position of the clicked article based on the returned array. For example, post-1320 would have an index of 0, post-1321 would return 1, post-1324 would return 2 etc.
Adding .index('.'+unqiuePostClass[1])
to the end of the code returns -1 because it can't locate the class.
HTML
<div class="one-third">
<article class="post post-1320">post-1320</article>
</div>
<div class="one-third">
<article class="post post-1321">post-1321</article>
</div>
<div class="one-third" style="display:none;">
<article class="post post-1322">post-1322</article>
</div>
<div class="one-third" style="display:none;">
<article class="post post-1323">post-1323</article>
</div>
<div class="one-third">
<article class="post post-1324">post-1324</article>
</div>
<div class="one-third">
<article class="post post-1325">post-1325</article>
</div>
<div class="one-third">
<article class="post post-1326">post-1326</article>
</div>
<div class="clear"></div>
JQuery
$('.post').click(function() {
var str = $(this).attr('class');
var unqiuePostClass = str.split(" "); // unqiuePostClass[1] returns post-xxxx
var result = $('.'+unqiuePostClass[1]).parent().siblings('.one-third:visible').addBack();
console.log(result);
});
RESULT
0: div.one-third
1: div.one-third
2: div.one-third
3: div.one-third
4: div.one-third
A JSFiddle which better demonstrates my problem: http://jsfiddle.net/lustre/rtf5L0gv/5/