Iterate and process child elements with jquery - proper use of $(this) -


i'm trying jquery find pairs of elements, take value of one, process , make value of next one, rinse , repeat.

        $(function() {                  $("div").each(function() {                 var longurl = $(this).attr("href");                 $(this).html("processed "+longurl);                 });          });      <div class="long" href="plop"></div>     <div class="short" href="plip"></div>     <div class="long" href="plopouze"></div> 

output :

processed plop processed plip processed plopouze 

so works, since selects divs, somehow proving each() can handle multiple objects ; fail understand how select $(this) objects using class selector, $(this).(.myclass) (in case $(this).('.short')) not work..?

if want check if $(this) has class .short can use $(this).is('.short').


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -