Placing More Than One Jquery Item on a Page
Permalink
I have a block I'm working on that uses a jquery plugin. To make the block work, it needs to have an embedded script to initiate the effect.
It works fine when only one of the block is added. However... when I go to add additional of the same block (but with different input), it creates a duplicate of the same of thing on the page.
How - for the love of egg nog - do I make it so that I can add more than one of the same block without any conflicts?
It works fine when only one of the block is added. However... when I go to add additional of the same block (but with different input), it creates a duplicate of the same of thing on the page.
How - for the love of egg nog - do I make it so that I can add more than one of the same block without any conflicts?
Are you using the addHeaderItem method to add your javascript in your block's controller?
No, i'm not. I just have the jquery file in a /js folder included with the block.
Ok, I tried this method, but same result. Maybe I'm doing it wrong. Any pointers?
Maybe just add the javascript file to the '/js' directory of the block? I believe this will get loaded automatically.
I tried that already. I think I will try a different approach: make it so that the block can be added only once to a page. How would I do this?
Have you had a play with ajax lessons? One of the outputs is a cross reference table of which script inclusion and calling methods work from what contexts. It won't solve your problem, but may provide some clues about what is happening.
http://www.concrete5.org/marketplace/addons/ajax-lessons/...
http://www.concrete5.org/marketplace/addons/ajax-lessons/...