Skip to main content

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

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. 

Share this post

Showing 4 reactions

How would you tag this suggestion?
Please check your e-mail for a link to activate your account.