Book chapters are nice extras, but journal articles are of greater value in almost all if not all fields. If you are hoping for an academic job, then I'd always favour putting your efforts into getting articles out over book chapters. My own employer for example has told us that book chapters won't count towards a REF submission, so if you are in the UK, I'd think very hard about it.
How do you get to write a book chapter? It's by invitation from the book's editor(s). Sometimes they come out of participation in a small workshop where an edited volume is planned as an output. Sometimes you get asked because you're regarded as the expert on something (or the most likely person to deliver a respectable chapter on time). Edited book projects can be a long time in the making, so it's often not a very quick or reliable way to get published.