Drupal 7: hiding/showing form api elements when a checkbox is checked or not

I was trying to make a file type element appear/disappear when a checkbox was checked or not.
When i added the ‘#states’ declaration in ‘myfile’ element it didn’t work as expected!
I had to add the ‘myfile’ element in a ‘container’ type element and add to that the ‘#states’ declaration.

  $form['want_to_upload'] = array(
        '#type' => 'checkbox',
        '#title' => t('Yes i want to upload a file'),

  $form['upload_container'] = array(
        '#type' => 'container',
        '#states' => array(
            "visible" => array(
                "input[name='want_to_upload']" => array("checked" => TRUE)),

  $form['upload_container']['myfile'] = array(
        '#type' => 'file',
        '#title' => t('Choose your file'),
        '#description' => t('You are allow to upload jpg, jpeg, png, gif and pdf, 5MB Max Size'),