javascript - Add data attribute to all images under a class -


i'm using lightbox requires specific tag inside link. don't want edit every post i'm trying automatically using jquery.

html

<div class="wrapper">    <a href="imagelink.png">image</a> </div> 

js

  $(document).ready(function() {  // scan classes $('.wrapper a').each(function(){      // apply tag     $(this).parent().attr('data-lity');  }); }); 

result should be

<div class="wrapper">    <a href="imagelink.png" data-lity>image</a> </div> 

jsfiddle http://jsfiddle.net/c2rvg/31/

this trick

jquery

$(document).ready(function() {      // scan webpage class names of 'thumb' seen.      $('.wrapper a').attr('data-lity', '');  }); 

enter image description here

demo


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -