0
I got the following code:
$("div.conteudo div.administrador form.administradorEdita")
Which is a
form
I want to refer to a label his;
var form = $("div.conteudo div.administrador form.administradorEdita");
How would it be?
form label#consulta
OR
$("form label#consulta")?
OR
$("form').label#consulta")?
?
I would like to take for example the text of label
But not only that element label.
There are several. That’s one form.
That one form has several fields where each field gets its own style. So:
$("div.conteudo div.administrador form.administradorEdita")
It would be a shortening of address for the form.
I need to understand the dynamics of how to shorten this address.
See how giant it gets:
// 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;
});
});
Does the label have an id? If so, the @Diegomarques response calmly resolves.
– Sam
Speak Carlos, I think the idea is this same, if you put an ID you do not need all of these paths. You search the element direct by the ID and ready...
– hugocsl
So I thought of something like below to shorten the select#type". var type = $("this select#type"). val();
– Carlos Rocha
or var type = $(this) + $("select#type"). val();
– Carlos Rocha