Question

<div class="links">
    <ul>
       <li class="pdf"></li>
       <li class="weiter"><a href="48">more</a></li>
    </ul>
</div>

For each LI.weiter, I want to grab the link add sth and append it as PDF-Link:

var LinkMarkup = '<a href="';
$('.weiter A').each(function() { 
   LinkMarkup += $(this).attr('href') + '&type=999" target="_blank">PDF</a>';  
   $(this).closest('.pdf').append($(LinkMarkup)); 
});

Thanks a lot!

Was it helpful?

Solution

Close, the anchor is a child of the li, to you can use find. The .pdf is actually a sibling, but is also the previous element, so use .prev. You also need to build the actual a element and append:

$('.weiter').each(function() { 
    var href = $(this).find("a").attr('href') + "&type=999",
        link = "<a href='" + href + "' target=_blank>PDF</a>";

    $(this).prev('.pdf').append(link); 
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top