Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I put jquery code inside a html document? (lightbox)

Tags:

jquery

How do I make the jquery show up in an existing html document? mainly the jquery lightbox plugin.

like image 236
Kevin Li Avatar asked Sep 08 '09 15:09

Kevin Li


People also ask

Where do we write jQuery code in HTML?

You can write it directly to the HTML doc inside <script> tags or link with <script src="javascript.

Does jQuery go inside script tag?

We can include the jQuery CDN URL in the script tag and use jQuery in HTML. We can either write the jQuery in a separate . js file and include it in the HTML file or write the jQuery inside the script tag. First, go to the JQuery CDN website and choose the latest stable version of the jQuery.


1 Answers

reference the jQuery script followed by the lightbox script in your html document.Like so,

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="source-of-jquery.js"></script>
<script type="text/javascript" src="source-of-lightbox-plugin.js"></script>
<script type="text/javascript" src="source-of-script-with-your-jquery-code-in.js"></script>
</head>
<body>

....

then you will need to use the lightbox accordingly. For example, in source-of-script-with-your-jquery-code-in.js

$(function() {
 $('#gallery a').lightBox({fixedNavigation:true});
});

binds the lightbox plugin to each <a> element that is a child of the element with the id gallery

EDIT:

jQuery is nothing but a JavaScript framework (albeit a great framework). If you're starting out on your front-end web development journey, I would suggest looking at JavaScript in conjunction with jQuery as it is the building block of the framework and will help you to understand how it works better. Here are some resources to get you started

  • good resources for learning javascript

  • best resources to learn javascript

like image 190
Russ Cam Avatar answered Nov 15 '22 01:11

Russ Cam