css - Find same text and add class to container with jQuery -



css - Find same text and add class to container with jQuery -

i’m trying find if of h2 texts matches h1 text. plus not beingness case sensitive. if finds match, add together class container product-div.

<div id="pageheader"> <h1>same text</h1> </div> <div class="product"> <h2 class="productname">product name 1</h2> </div> <div class="product"> <h2 class="productname">same text</h2> </div> <div class="product"> <h2 class="productname">product name 2</h2> </div>

you can seek below. read h1 text , create lowecase ( said text compare not case sensitive). iterate h2 , compare text h1, if matches add together class parent div.

$(function(){ var h1text = $('#pageheader h1').text().tolowercase(); $('.product .productname').each(function(){ if($(this).text().tolowercase()==h1text) $(this).closest('.product').addclass('containerprod'); }); });

demo

jquery css match case-sensitive

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -