What does this mean? **input[name=checkListItem]**


#1
$(document).ready(function() {
    $('#button').click(function() {
       var toAdd = $('input[name=checkListItem]').val();
        });
    });

In the above jQuery code what does input[name=checkListItem] mean?


#2

Hi Saif,

That's a CSS attribute selector. We've got this HTML:

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

in the example, and so there are a couple different ways we could select it without modifying it, but two main ways:

  1. By tag name, like $('input')
  2. Attribute selecting, like $('[name="checkListItem"]')

You can see more on CSS attribute selectors here.

I hope this helps :)


#3

thanks zystvan. i was completely lost as to why that works