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
Post a Comment