Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kruxor/adb96132c9a3a706ce8f to your computer and use it in GitHub Desktop.
Save kruxor/adb96132c9a3a706ce8f to your computer and use it in GitHub Desktop.
Loop through divs with the same class name and append something
<div class='click-target'>a click target</div>
<div class='click-target'>another click target</div>
<div class='click-target'>and another click target</div>

Loop through divs with the same class name and append something

Pretty much the title, good id you have a ton of the same divs and you need to append a common link or something.

A Pen by Luke on CodePen.

License.

if($('.click-target').length) {
$(".click-target").each(function(){
$(this).append("<p>Added!</p>");
});
}
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment