this question has answer here:
- get “id” , add in each div (name = “id”) 3 answers
i'm still learning, i'm racking brain.
$('.post-outer .post-footer .post-footer-line.post-footer-line-2 .post-labels a').each(function(index, el) { $('.post-outer').attr('itemtype', $(this).attr('href') ); }); when run js above takes first "href" repeating in other "div". going on:
<div class="post-outer" id="001" itemtype="url1">test1</div> <div class="post-outer" id="002" itemtype="url1">test2</div> <div class="post-outer" id="003" itemtype="url1">test3</div> i wanted happen this:
<div class="post-outer" id="001" itemtype="url1">test1</div> <div class="post-outer" id="002" itemtype="url2">test2</div> <div class="post-outer" id="003" itemtype="url3">test3</div> here in example takes last div , repeated in other https://jsfiddle.net/mpb9wfmc/
using .each can use this current element iterated though:
$(this).attr('itemtype', newvaluehere ); doing $('.post-outer').attr('itemtype', $(this).attr('href') ); apply items class post-outer.
Comments
Post a Comment