MegaXLR MegaXLR - 6 months ago 32
CoffeeScript Question

Selecting element its value in coffeescript

I want to select an element based on its name and get its value.

I currently have:

document.getElementsByName 'employee_search_first_name'[0].value

which compiles to:


But I need:


To make my situation a bit clearer:

  • I do not have access to jQuery or any framework for that matter.

  • I do not want to store the element in a variable as I need more than just this one.

What would be the valid coffeescript to get this?


Parentheses are optional in CoffeeScript, unless they're not. This is a case where you need the parentheses to disambiguate:


Yes, this is valid CoffeeScript.