Clean input label within a DIV?

1

Dear, greetings to all! Maybe it's a bit basic, but I'd rather be sure and ask.

I have a div in which I have ordered several input , some of them label , in which I refer to a input file , in this way;

<table class="title">
    <tr>
        <td style="width: 20%" >
            <input class="" value="1" type="checkbox" name="tipo_cert[]" id="tipo_cert_1" />
            <label for="tipo_cert_1">Para subir archivo</label>
        </td>
    </tr>
</table>
<br/><br/>
<div id="arch1" style="display: none;">
  <div id='file1' class="file">
    <input type="hidden" class="txtFile1" name="txtFile1" value="" />
    <label class="text" id='text1' for="6_1_adjn">Seleccione un archivo</label>
    <label for="6_1_adjn" >
        <input id="6_1_adjn" name="6_1_adjn"  class='fileInput required' type="file" value="" />    
    </label>
  </div>
</div>

By means of a checkbox , I make appear and disappear a div that contains this code. Then when you click on this checkbox and disappear this, you should clean all the input of this div . And that's where I'm stuck. I clean the hidden , I can unmark the checkbox but I can not clean the label and if I put a .val('') to input file it says: 'security issue', therefore with input file I'm not going to put =) haha

My JS code;

$('#tipo_cert_1').on('change', function () {
  if ($('#tipo_cert_1').is(':checked') == true) {
    $("#arch1").attr('style', 'display: block;');
  }else{
    $("#arch1").attr('style', 'display: none;');

    $("#arch1 input[type=checkbox]").prop("checked", false);
    // $("#arch1 input[type=label]").text("");
    // $("#arch1 input:label").text("");

  }
});

Now, does it affect that this label is within a div that is within another div ? A question that perhaps is the reason why I can not clean or reach this label .

Dear, this is my concern. Once a teacher told me that the only question is the ONE that is NOT asked.

    
asked by x_Mario 16.03.2016 в 13:44
source

1 answer

1

The label are not a type of input , they are HTML tags like any other, if you want to change their name to label just use them like any other tag:

$("#arch1 label").text("");

Keep in mind that the above will change the text of all label . If you want to use a specific one, you can use the id , the class or take advantage of the art% for of label :

$("#arch1 #text1").text("");
$("#arch1 label.text").text("");
$("#arch1 label[for=6_1_adjn]").text("");
  

Now, does it affect the label that is inside a div that is inside another div?

No, the search is performed with respect to all "children" of #arch1

    
answered by 16.03.2016 / 13:55
source