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.

0

2 Answers 2

15

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

Sign up to request clarification or add additional context in comments.

Comments

10

try this:

var id = document.getElementsByClassName("hid_id")[0].value;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.