Shorten address of a group of elements with jQuery

0

I have the following code :

$("div.conteudo div.administrador form.administradorEdita")

What is one

form

I want to reference a label of it;

var form = $("div.conteudo div.administrador form.administradorEdita");

What would it be like?

form label#consulta 

OR

$("form label#consulta")?

OR

$("form').label#consulta")?

?

I would like to get the text of the label

But you do not just have this label element.

There are several. This is a form .

This form has several fields where each field gains its own style. Then:

$("div.conteudo div.administrador form.administradorEdita")

It would be an address shortening for the form.

I need to understand the dynamics of how to shorten that address.

Here's how it looks:

// JavaScript Document
$(document).ready(function(e) {

  $("div.conteudo div.administrador form.administradorCadastra").on("submit", function() {

      var tipo = $("div.conteudo div.administrador form.administradorCadastra select#tipo").val();
      var nome = $("div.conteudo div.administrador form.administradorCadastra input[type=text]#nome").val();
      var login = $("div.conteudo div.administrador form.administradorCadastra input[type=text]#login").val();
      var senha = $("div.conteudo div.administrador form.administradorCadastra input[type=password]#senha").val();

      if ( tipo == "" ||
           nome == "" || 
           login == "" || 
           senha == "") {

          alert("Algum campo está vazio!");

          return false;

       } 

         $("div.conteudo div.administrador form.administradorCadastra input[type=submit].btnAcesso").css('display', 'none');
         $("div.conteudo div.administrador form.administradorCadastra img").css('display', 'block');

         $.post ("../_requeridos/cadastraAdministrador.php", {

             tipo    : tipo,
             nome    : nome,
             login   : login,
             senha   : senha

         }, function(retorno){


             $("div.conteudo div.administrador form.administradorCadastra input[type=submit].btnAcesso").css('display', 'block');
             $("div.conteudo div.administrador form.administradorCadastra img").css('display', 'none');

              if (retorno == 1) {
                resposta = "Cadastrado com sucesso!";
              } else {
                resposta = "Erro no cadastro";
              }
             $(".resposta").css("display", "block");
             $(".resposta").html(resposta);     

           }
          );

          return false;

    });

});
    
asked by anonymous 22.05.2018 / 23:01

1 answer

1

If the label has an ID, and the ID must be unique in an HTML document, you can take it directly by the ID. Example:

$("#consulta");

To get the text you can use the "text()" function. Example:

$("#consulta").text();
    
22.05.2018 / 23:07