views:

56

answers:

1

I'm trying to modify Brian Reindel's Accessible News Slider plugin (sorry, it won't let me link to it and also to my work location), to allow a visitor to fill in multiple copies of a form, sliding back and forth between them. I need for the visitor to be able to add and delete copies of the form from the list. I've modified one of his examples and created a little function to add an element to the list. However, no matter how many times I call the function, it only adds one element, and the plugin is not aware of it; I can see it in the DOM Inspector, but that's it. What am I missing?

+1  A: 

Hi Alan, this is Brian. Since you're already using jQuery and the plugin, you would gain a great deal by using the library to append elements to the DOM within your custom function. I wanted to give you some guidance, since this is probably more work than you were inititally expecting. Here are some hopefully helpful tips:

  • The plugin calculates some wrapper element widths based upon the number of list items. If you add/remove list items, then you would need to modify the calculations that were made or else it won't scroll properly. You'll probably experience the same types of issues for the click events on the next/previous buttons.
  • If you have events registered on elements that you add/remove from the DOM, then you will need to re-register those events, since when the elements are gone, so are the events that were "bound" to them. It doesn't look like this is your problem though at this point.
  • If you're adding form elements to the DOM on the fly using the "Add" link, then the user's cursor focus is no longer on the form elements, and the slider is no longer really accessible. As much as I love plugging my own plugin, it was meant mostly to demonstrate usable, custom styled accessible JavaScript, and I'm not sure it is flexible enough to do what you want without some rework.

If you have more specific questions about how to do certain things to get you started on the right track, let me know, and I would be happy to help. Depending on how much you plan to use jQuery on your projects (and I highly recommend that you use it), try out the book Learning jQuery.

hal10001
I work with Brian. If this answer does not suffice, I will have a monkey thrown at him.
Shaun F
Brian and Shaun, thanks very much for your responses. If you could point me to specific functions or methods to use, that would be greatly appreciated. I am interested in learning jQuery, but am in a bit of a time crunch on this, so while no monkeys are necessary, and I don't expect anyone to do my work on this, specifics would be greatly appreciated.
Alan Little
P.S. Are there any sites with a "Hello World!" approach to learning jQuery? I find many sites which show how to do many things with jQuery, including the one linked from Brian's site, but none of them so much as say what jQuery is! I can't find anything on how to get started with it.
Alan Little
Alan - How about this http://docs.jquery.com/Tutorials:How_jQuery_Works
Shaun F
Thanks, guys. I ended up starting from scratch; I was able to understand enough of Brian's plugin to get the basic idea of what it's doing, and built my own solution, not as elegant, but functional. I did end up using the animate() method from jQuery, and figuring out how to do that clarified a few things about jQuery in general. I must say though, that even the documentation on the jQuery site is confusing. It doesn't explain anything, just jumps right into doing things. I had no idea what the $ was, for example. Anyway, good to go now, and I look forward to learning more about jQuery.
Alan Little