The next 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">
</a>
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) {
e.preventDefault();
var inputs = (this).getElementsByTagName('input');
console.log(inputs[0]);
var asociado = inputs[0].attr('value');
console.log(asociado);
});
But I have not managed to enter the input.
Don't use
attr
use val insteadExplanation:
In this case
var inputs = (this).getElementsByTagName
inputs
it is not a jQuery object , so it does not have any associated jQuery method.Instead, when invoked
inputs =$('input')
, a wrapper is added that convertsinputs
to a jQuery object and tests your object for all available methods.To get the value (value attribute) of a field
input
orselect
ortextarea
useval()
See jQuery documentation .You must create a jQuery object with the element you get in , this way you can use the jQuery
inputs
method .val()
More information about jQuery objects at the following link: http://api.jquery.com/jQuery/
You could also do it this way, assuming you don't need the inputs variable afterwards: