bem-site / bem-forum-content-en

Content BEM forum for English speak users
3 stars 0 forks source link

How to write js for blocks #31

Open FrancisVega opened 8 years ago

FrancisVega commented 8 years ago

Hi all! Is there any guide or examples to write plain js for blocks?

Thanks!

tadatuta commented 8 years ago

@FrancisVega hi!

What do you mean by plain js for blocks? Main idea is to use same selectors in JS as you use in CSS. You may also keep JS files of each block in block's folder as well as CSS and any other techs (see https://en.bem.info/method/filesystem/).

But you may also use some libraries. E.g. here's a jQuery plugin to easily work with blocks, elements and modifiers: http://xslc.org/jquery-bem/

Or you may take a look at more powerful solution called i-bem.js: https://en.bem.info/technology/i-bem/v2/i-bem-js/

ihorzenich commented 8 years ago

@FrancisVega

vithar commented 8 years ago

Using js- prefix is bad practice, try to avoid it. Just use the same class for css and js functionality.