append - JQuery. Copy link attribute to a dynamic element within a div -
i'm still learnig jquery , i'm stuck trying have each of dynamically generated links same url previous static link within div. code seems apply same url (#1) generated links, when on sec div need #2.
code:
$(document).ready(function() { $('.sorter > div p').append('<a class="rdm">read more</a>'); $('a.rdm').each(function() { var lnk = $('.sorter > div').find('a').attr('href'); $(this).attr('href', '' + lnk); }); });
html:
<div class="sorter"> <div><a href="#1">link a</a><p>some text </p></div><br /><br /> <div><a href="#2">link b</a><p>some text </p></div> </div>
many help!
oh think need one: http://jsfiddle.net/gsgz5/
var lnk = $(this).parent().siblings('a').attr('href'); //<--get href way $(this).attr('href', lnk);
jquery append href attr
No comments:
Post a Comment