javascript – How to get value from an input using jquery?


The following line:

<a id="asociar-1500" style='color: #004881' href="#" title='Asociar al Proveedor' class="btn btn-danger"><input type="hidden" value = "true"></>

It generates the following HTML:

<a id="aosciar" class="btn btn-danger" title="Asociar al Proveedor" href="#" style="color: #004881">
<input type="hidden" value="true">

I would like to know how to obtain the Value of the Input that is in Hidden , for that I am testing with this jquery function:

$('a[id^=asociar-]').click(function (e) {


var inputs = (this).getElementsByTagName('input');

var asociado = inputs[0].attr('value');



But I have not managed to enter the input.


Don't use attr use val instead

var asociado = inputs[0].val();// es como un get

If you change var inputs = (this) .getElementsByTagName ('input'); by var inputs = $ ('input')


In this case var inputs = (this).getElementsByTagName inputs is not a jQuery object , therefore it does not have any associated jQuery method

On the other hand, when inputs =$('input') is invoked, a wrapper is added that converts inputs to a jQuery object and tests your object for all the available methods

Scroll to Top