Can someone help me understand why var toAdd = $('input[name=checkListItem]').val()


I did this correctly (or at least I'm under the impression I did as I passed the exercise), but I don't really understand the [ ] part of this code... what is this actually doing? Thanks!


//// this part:

    var toAdd = $('input[name=checkListItem]').val();



Hi Justine,

It's a CSS attribute selector. In this case, we have something like this:

<input type="text" name="checkListItem">

Since there's no way by default to select that specific element using CSS, you can use a CSS attribute selector like so:

input[name="checkListItem"] {
  /* styles */

You can see more information here:


Thank you for the explanation and the mdn link - it's very helpful!


This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.