Delete label text with jquery

1

I need to delete the text contained within the label tag ("Justification") with jquery, follow the code:

function add_text() {
  if ($("#tipo").val() == "Falta") {
    $(".b").remove();
    $("#just").remove();
    $("#justificativa").remove();
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><selectid="tipo" name="tipo" onchange="add_text()"><option>Falta</option><option>Falta Justificada</option><option>Fardamento Incompleto</option><option selected="">Entrada/Saída Autorizada</option><option>Indisciplína/Outros</option></select><br>
<label>Justificativa: </label><br><textarea required placeholder='Digite a justificativa do aluno...' title='Seja objetivo(a).' rows='5' name='obs' cols='50' id='justificativa'></textarea>
    
asked by anonymous 31.08.2017 / 03:47

1 answer

2

Add an ID to the label

<label id="label-justificativa">Justificativa: </label>

Add to your js

$("#label-justificativa").remove();

-

I think you can improve your code:

    function add_text(){     
    	if($("#tipo").val()=="Falta"){
             $(".b").remove();
             $("#just").remove();
             $("#opcoes").hide();
        }
        else{
        	$("#opcoes").show()
        }
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><selectid="tipo" name="tipo" onchange="add_text()">
       <option>Falta</option>
       <option>Falta Justificada</option>
       <option>Fardamento Incompleto</option>
       <option selected="">Entrada/Saída Autorizada</option>
       <option>Indisciplína/Outros</option>
    </select>
    <div id="opcoes">
       <label>Justificativa: </label><br>
       <textarea required placeholder='Digite a justificativa do aluno...'
       title='Seja objetivo(a).' rows='5' name = 'obs' cols='50' 
       id='justificativa'></textarea>
    </div>

I made a modification that it is only hidden when the value selected is "Missing"

So you remove an entire block instead of looking for the tags you want to remove, I see it as a simpler solution

You can also use hide () to hide the html, so if you want to view it again use the show () .

    
31.08.2017 / 03:59