0

Is this jquery/javascript statement correct and valid.

$('.icon_edit').click(function(){
  $(this).parent().hide().siblings('span').hide();
});
<div class="dataBox">
 <span>
  <input class="chkbox" type="checkbox"/>
 </span>
 <span class="memName">test1</span>
 <span class="memNum">9791091380</span>
 <span class="memDesc">test 1</span>
 <span>
  <a class="icon-delete" >&nbsp;</a>
  <a class="icon-edit" >&nbsp;</a>
 </span>
 <div>
  <input class="editName"/>
  <input class="editNum"/>
  <input class="editDesc"/>
 </div>
</div>

I was actually trying to hide the selected elements parent + all the siblings of the parent which are 'span' element in a single statement. Is there a better way to do this.? NB:Actually this code is working for me. But not sure if its violating any syntax or selection rules of javascript/jquery.This is how I did it in 2 statements

$(this).parent().hide().siblings('span').hide();
$(this).parent().hide();
Johnson
  • 118
  • 1
  • 11

1 Answers1

1

This is an alternative approach,

$(this).parent().siblings('span').andSelf().hide();

Fiddle

Anoop Joshi P
  • 25,373
  • 8
  • 32
  • 53