javascript - jQuery function to loop through elements and set class names based on order compared to an element with a specific class name -


current codepen: http://codepen.io/anon/pen/rvnpvg

<div class="box">box1</div> <div class="box">box2</div> <div class="box active">box3</div> <div class="box">box4</div> <div class="box">box5</div> 

i'm working on best way , love input.

i'm writing function loop through set of elements have class name of box. 1 of elements in list have class name of active. elements prior 1 active class, want set class name of done. of elements after 1 active class, want set class name of hidden.

the way i've done seems unnecessarily iterative , i'm wondering if can provide elegant method.

any appreciated.

thank in advance time!

var $activebox = $('.box.active'); $activebox.prevall('.box').addclass('done'); $activebox.nextall('.box').addclass('hidden'); 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -