jQuery - If previous element doesnt have specific class then remove that element -


i wrote code, doesnt work.

goal:

  1. if span previous ".well-well" not ".dont-remove" remove span

  2. however if span previous ".well-well" ".dont-remove" nothing

"example" here:

http://jsfiddle.net/saebr/

if( $(".well-well").prev('span').not('.dont-remove') ){ $(".well-well").prev('span').remove(); } 

what im getting code removes spans previous ".well-well" , have no idea why.

what doing wrong?

you don't need if:

$(".well-well").prev('span').not('.dont-remove').remove() 

what code is:

if ($(".well-well").prev('span').not('.dont-remove') != null)  {  //remove them } 

don't worry if. remove() function after that.

http://jsfiddle.net/saebr/2/


Comments