Happydevdays Happydevdays -4 years ago 105
HTML Question

jquery - identify items by class and then extract value

I have the following hidden input field on my form:

<input class="dow" id="hidden_dow0" type="hidden" value="m,t,w,r,f,s,n">

Once the form has loaded I need to find this hidden control, extract the value... and then use each item in the list ('m,t,w ') to set corresponding checkboxes on

So far, I have been able to find all hidden inputs, but I don't know how to extract the value from it.

Here's what I have so far:

$('.dow ').each(function (i, row) {
var $row = $(row);
var $ext = $row.find('input[value*=""]');
console.log($ext.val); //fails.


This is I tried:

//find all items that have class "dow" ... and
$('.dow ').each(function (i, row) {
var $row = $(row);
console.log(row); //prints the <input> control
//var $ext = $row.find('input[value*=""]');
var $ext = $row.find('input[type="hidden"]');
console.log($ext); //prints an object
$ext.each(function() {
console.log( $(this).val() ); //does not work

Answer Source

In jQuery val() is a function.
The .dow element is the input, you don't need to find it

$('.dow ').each(function (i, row) {
    console.log( $(this).val() );  //works
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download