Help to enter please. There is such a html.

<span>ddd</span><button id="a" class="aaa bbb"><i class="ccc eee"></i></button> 

Js fragment

 $('#a').removeClass('aaa'); 

How can I add that in the same line to remove the class "ccc" from the tag that is inside this button and the full span tag before the button?

  • Have you forgotten to do anything here? ru.stackoverflow.com/a/881658/176262 - Igor
  • And it seemed to me that this is in two accounts on the Internet - Vitaly Shebanits
  • You obviously need to read the section on jQuery - selection of objects by the selector - Vitaly Shebanits

1 answer 1

 $('#a').removeClass('aaa').find("i").removeClass('ccc'); 

as if before the button you still need to completely delete

 $('#a').click(function(e) { $(this).removeClass('aaa').find("i").removeClass('ccc').closest("button").prev("span").remove(); }); 
 .ccc { color: green; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <span>ddd</span> <button id="a" class="aaa bbb"> <i class="ccc eee">Test</i> </button> 


not the whole span, but only the text inside it

 $('#a').click(function(e) { $(this).removeClass('aaa').find("i").removeClass('ccc').closest("button").prev("span").text(""); }); 
 .ccc { color: green; } .span-class { border: 1px solid black; padding-left:10px; padding-right:10px; background: lightgreen; } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <span class="span-class">ddd</span> <button id="a" class="aaa bbb"> <i class="ccc eee">Test</i> </button> 

  • Thank! But what if before the button there is another <span> </ span> that you need to delete? - I Zrchnsk
  • and all in one line - I Zrchnsk
  • @IZrchnsk Please add html to the question. - Igor
  • as it is not immediately removed ... but by repeated action - I Zrchnsk
  • @IZrchnsk I - right away. - Igor