JavaScript onclick?

Sorry if this is a noob question -- I'm new to JavaScript. Tonight I was creating a NationBuilder page with a couple of embedded images that I wanted to enlarge when the user clicked on them. Seems like a perfect job for JavaScript.

I see on NB's page that you're supposed to put JavaScript in the template, not in the html editor. But, AFAIK, I need an onclick event in the <img> element in order to to trigger JavaScript, and that element isn't available in the template since the content is all pulled in as page.basic.content. Am I missing something? 

Official response from Jesse Haff

What you want to use is a jQuery light box plugin. There are tons of different varieties of those scripts, just search Google and choose the one you like the best. They are usually triggered by a class in the img tag, not an onClick event. 

The the jQuery needs to go in a template, and depending on how extensive the HTML is for the page, you may want to put all the content in the template of the page as well, instead of the content editor. For example if you are trying to create an image gallery, I'd build that all within the template of the page. If the page will be mainly text with a couple images, you should probably do that in the content editor. 

How would you tag this suggestion?
Do you like this suggestion?

Showing 6 reactions


Lilia Villa tagged this with Answered 2012-05-15 09:52:31 -0700
Brad Johnson commented 2012-03-26 08:47:56 -0700
Martha, I included my JavaScript by uploading the script to Theme -> Files, instead of pasting it in using New File. Uploading gets around the file type restrictions. Then I linked to the script in the footer. You might want to see: http://nationbuilder.com/demodirect/javascript_resources
Martha White commented 2012-03-25 23:03:53 -0700
I would love to do the same thing, but am confused where the .js code can be put. I want to add a Picasa album using PWI, which would involve adding several jquery.pwi.js files to my theme files so I can reference then in my page template. But, only .html, .txt, .scss and .css files are allowed. What am I missing? Sorry, I am a complete nube, I’m learning as I go :)
Brad Johnson commented 2012-02-17 11:01:04 -0800
Thank you! This is the 2nd time I’ve run into jQuery. Need to dig into it. . .
Brad Johnson tagged this with Helpful 2012-02-17 11:00:17 -0800
Jesse Haff responded 2012-02-17 06:41:48 -0800

What you want to use is a jQuery light box plugin. There are tons of different varieties of those scripts, just search Google and choose the one you like the best. They are usually triggered by a class in the img tag, not an onClick event. 

The the jQuery needs to go in a template, and depending on how extensive the HTML is for the page, you may want to put all the content in the template of the page as well, instead of the content editor. For example if you are trying to create an image gallery, I'd build that all within the template of the page. If the page will be mainly text with a couple images, you should probably do that in the content editor. 

Join our team
We're hiring great software developers and organizers. Learn more →