How to add a class to a span element which is part of an existing <li> tag with jQuery

How can I add a class to a span element for only these spans which are part of li tags with class='error'
per example, this is the HTML which is generated:

<li class="error">
  <!--if list has class error, then add also class error to span which is part of that list tag-->
  <span class="error"></span>
</li>

This is the code I have so far:

if(status == 'error') {
  data.context.addClass('error'); // adds class error to li tag                 
}

15 thoughts on “How to add a class to a span element which is part of an existing <li> tag with jQuery”

Leave a Comment