0

I have a javascript snippet in which I'd like to retrieve the value of a hidden input located in the first column of selected row :

var global_id = $(this).find("td:first").html();
console.log("value=" + global_id);

I get as result :

value =<input id="id" name="id" type="hidden" value="2">

When I try

 var global_id = $(this).find("td:first").val();
console.log("value=" + global_id);

I get as result :

value =

So, I need to know :

  1. Why in the second way, the variable is empty
  2. How can I resolve my code to retrieve the first input hidden value?
1
  • EDITED: Just noticed your middle result update. Tiny Giant has the answer anyway Commented Jun 17, 2015 at 23:02

1 Answer 1

6

You need to reference the actual input element, not the containing element. This will find the input element if it is hidden using type="hidden", using css or using jQuery's hide()

var global_id = $("td:first input:hidden:first", this).val();
console.log("value=" + global_id);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.