jquery - Add attribute with increasing values -


i have html:

<article id="2332">content...</article> <article id="0565">content...</article> <article id="5686">content...</article> 

i want add attribute "scroll-index" increasing numbers. result, should be

    <article id="2332" data-scroll-index="0">content...</article>     <article id="0565" data-scroll-index="1">content...</article>     <article id="5686" data-scroll-index="2">content...</article> 

i trying jquery code:

var scrollindex = 0; $('article').each(function() {     $(this).attr('data-scroll-index', scrollindex);     scrollindex++; }); 

but no accomplishment. auggestions?


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -