Need a little help from you guy’s. I am making a check where element is. First if statement is working , but else if is not… I have tried even something like this but it doesn’t work:
else if(($('.current').prev().hasClass('green')){
alert('Green is Before the current Picture');
}
I want to accomplish this: if green is before class “current” alert “Green is Before the current Picture’s”.
Can someone help me out? Thank you!
Here is Fiddle.
I have this code:
var $green=$('.green:not(:nth-child(6))');
$('.greencontroll').click(function(){
if($green.next($('.current').length)){
alert('Green is After the current Picture');
}
else if($green.prev($('.current').length)){
alert('Green is Before the current Picture');
}
Assuming the elements are siblings:
The problem with your code is that
prevjust gets the sibling immediately prior to the element, not all prior siblings.