There are blocks

<div><h1>Текст заголовока</h1></div> <div><h1>Текст заголовока<b> жирный текст</b></h1></div> 

I want to ensure that a text class is added to each text tag.

Text tag is a tag that has only text value, maximum icon <i>

My code is:

 $(':not(:has(*),:empty)').addClass('text'); 

It works only for the first h1 , but for the second it adds only to the tag b. How to improve the jquery sample in my example? I also want to clarify that tags can be any like a span or p, not the essence) Thanks in advance!

  • $("h1").addClass('text'); - Grundy
  • Give a definition for the term: text tag . And decide on which elements you want to add a class. - Grundy
  • @Grundy, I wrote that the tag can be any, the code should not depend on one specific tag - Sdafs Fasafs
  • A text tag is a tag that has only text in meaning, the maximum icon is <i> - so the second h1 is not a text tag, since <b> it is not <i> therefore it works the way you want - Grundy
  • @Grundy, a small amendment, text tags can also be in the text, I mean b, span, p, strong, small, etc., such tags that can be nested in the text - Sdafs Fasafs

0