13

Sorry, it's basic one but I trying to search on google anyways but still not get success.

I want get value of this

<input type='hidden' class='hid_id' value='1' />

Using Javascript I want alert value 1

I trying this

var id = document.getElementsByClassName("hid_id");
alert (id);

But it's alert [object HTMLInputElement]

please help me now.

Songs
  • 267
  • 1
  • 2
  • 13

2 Answers2

12

getElementsByClassName() returns an array so you have to access first element (if there is any). Then try accessing value property:

var id = document.getElementsByClassName("hid_id");
if (id.length > 0) {
    alert (id[0].value);
}

jsfiddle

Keammoort
  • 3,055
  • 17
  • 20
9

try this:

var id = document.getElementsByClassName("hid_id")[0].value;
madox2
  • 45,325
  • 15
  • 94
  • 95