ab11 ab11 - 1 year ago 73
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");

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download