I have a page with duplicate ID\'s for a form element. The catch is I the elements show up separately based on a toggle. So both ID\'s never show up simultaneously.
as Rwwl said, duplicate IDs are invalid. Assign classes instead of ids to them.
Then you can do
alert($('.my_element:visible').val());