Create functions dynamically
I am reading from a database and read the number of elements from a text box at the end of the program (line 3). This is not working, but is there a way to achieve the same result? (assuming that there is no errors in my syntax).
Thank you in advance
- <script type="text/javascript">
- $("document").ready(function(){
- var total = $("#number_of_elements").val();
- var name_header = "";
- var name_div = "";
- for(var i=1;i<=total;i=i+1){
- name_header = ".top_header" + i;
- name_div = ".top" + i;
- alert(name_header + " " + name_div);
- $(name_header).click(function(){
- $(name_div).slideUp(200);
- });
- }
- });
- </script