Q:

How to find the div which contains some word with exact match

I have checked the following link:
jQuery :contains(), but to match an exact string
But once I find the div i have to set attribute:
 $('#viewer .textLayer div:contains('+hotspot_draw_join+')').each(function () {
            $(this).attr('class','secondtypehotspot secondtypehotspot_ref'); 
            $(this).attr('id',hotspotstr);
            $(this).attr('onclick','secondtypehotspotfn(event)');

           });

How do i do that using filter option

A:

You can try like this.It's working fine.
 <div id="id">
     <p>John</p>
     <p>Johny</p>
 </div>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
 <script>
     var results = $('#id').find('*').filter(function () {
         if ($(this).text() === 'John') {
             $(this).attr("data-val", "hello");
             return $(this).text() === 'John';
         }
     });
     results.css('color', 'red');
 </script>

