jquery - Is there a way to reference an input element immediately before a javascript function WITHOUT using its ID? -
when calling function page in javascript, there way reference element before function without id? example,
<select>...</select> <script type="text/javascript"> my_function(previous_element); </script>
is there way send select element my_function() without using id of select element?
thanks in advance.
edit: more information on trying do.
i'm using rails plugin generates copy of group of form elements unique id each element. i'm trying call function particular form (select) element within group - ideally add onload select element, doesn't exist form elements. calling function within page best can come with. since elements copied using ajax (iow "add new address" kind of thing), if added element known id copied (and create multiple elements same id, , confusion). know it's messy i'm having difficulty coming solution, , plugin integrated project.
since using nested_forms gem, , want access specific element after dynamically added form, try following?
in head section of html, after included nested_form.js file, put javascript (you can use rails content_for method or put in javascript file , include it):
<script type="text/javascript"> $(function() { $('form a.add_nested_fields').live('click', function() { var form = $(this).parent(); // form // can traverse dom searching specific element }); }); </script>
i haven't tested code, think event execute after children fields have been added. since can access form inside event, can traverse dom search specific element trying access.
hope helps!
Comments
Post a Comment