ab11 ab11 - 7 months ago 19
Javascript Question

jQuery: how to retrieve element by concatenated ID?

I am dynamically creating and generating their id's to be something like


In the below Javascript code,
var hid
is retrieved properly by
. But the jQuery line below has a syntax error. How can I retrieve this element by Id using jQuery?

var hid = document.getElementById('hidden'+id);
var hidden = $("#'hidden'+id");


It's just a simple typo:

var hidden = $('#hidden'+id);

You want to select an element with the id 'hidden' + id. The according CSS / jQuery selector therefore looks like '#hidden' + id.