How can I get the value that I have inside is input?
<p id="1">1 <input value="" type="text"></p>
How can I get the value that I have inside is input?
<p id="1">1 <input value="" type="text"></p>
Try searching for the element with the id 1
that would be the element p
and then the input
:
function obtenerValor()
{
console.log($("#1 input").val());
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="1">1 <input value="" type="text"></p>
<button onclick='obtenerValor()'>Obtener valor</button>
If it is for a field type of text or numeric, it would be done with .val()
If you want to get the text contained within a html element, it is done with a .text()
Like this:
function obtenerValorDeCampo()
{
console.log($("#campo").val());
}
function obtenerValorDeElemento()
{
console.log($("#1").text());
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="1">1 <input id="campo" value="" type="text"></p>
<button onclick='obtenerValorDeCampo()'>Obtener valor de campo</button>
<button onclick='obtenerValorDeElemento()'>Obtener valor de elemento</button>