Passing object (array) ob form element IDs as function parameter and accessing via jQuery
Hi all,
up until now I have been able to pass the element ID of a form element to a javascript function and access via jQuery as follows:
- var elem_id = document.getElementById( 'my-form-element' );
- doStuff( $( elem_id ) );
- ...
- function doStuff( $elem_id ) {
- $elem_id.val( 'Text' );
- }
...this all works fine.
However, now I have an object of element IDs that I want to pass and cannot access the individual elements via jQuery.
I have tried the following:
- var elem_ids = {
- first_id: document.getElementById( 'my-first-form-element' ),
- second_id: document.getElementById( 'my-second-form-element' )
- };
- doStuff( elem_ids );
- ...
- function doStuff( elem_ids ) {
- $( elem_ids.first_id ).val( 'Text' );
- }
...but this does not work :( I want to be able to send the array/object of IDs so that I do not have to pass all of the element IDs as individual parameters.
Can this be done?
Thanks in advance.