Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add jQuery code into HTML Page

$(".icon-bg").click(function () {      $(".btn").toggleClass("active");      $(".icon-bg").toggleClass("active");      $(".container").toggleClass("active");      $(".box-upload").toggleClass("active");      $(".box-caption").toggleClass("active");      $(".box-tags").toggleClass("active");      $(".private").toggleClass("active");      $(".set-time-limit").toggleClass("active");      $(".button").toggleClass("active");  });    $(".button").click(function () {      $(".button-overlay").toggleClass("active");  });    $(".iconmelon").click(function () {      $(".box-upload-ing").toggleClass("active");      $(".iconmelon-loaded").toggleClass("active");  });    $(".private").click(function () {      $(".private-overlay").addClass("active");      $(".private-overlay-wave").addClass("active");  });

Can anyone help? It's for an upload function I found at http://codepen.io/iremlopsum/pen/YPWPap. Trying to get it into my website

like image 483
justin_graham92 Avatar asked Apr 22 '15 11:04

justin_graham92


People also ask

What are the two ways to include jQuery?

There are two ways to include jQuery in a project, which is to download a local copy or link to a file via Content Delivery Network (CDN).


1 Answers

1) Best practice is to make new javascript file like my.js. Make this file into your js folder in root directory -> js/my.js . 2) In my.js file add your code inside of $(document).ready(function(){}) scope.

$(document).ready(function(){     $(".icon-bg").click(function () {         $(".btn").toggleClass("active");         $(".icon-bg").toggleClass("active");         $(".container").toggleClass("active");         $(".box-upload").toggleClass("active");         $(".box-caption").toggleClass("active");         $(".box-tags").toggleClass("active");         $(".private").toggleClass("active");         $(".set-time-limit").toggleClass("active");         $(".button").toggleClass("active");     });      $(".button").click(function () {         $(".button-overlay").toggleClass("active");     });      $(".iconmelon").click(function () {         $(".box-upload-ing").toggleClass("active");         $(".iconmelon-loaded").toggleClass("active");     });      $(".private").click(function () {         $(".private-overlay").addClass("active");         $(".private-overlay-wave").addClass("active");     }); }); 

3) add your new js file into your html

<head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <script src="/js/my.js"></script> </head> 
like image 110
nikssa23 Avatar answered Sep 18 '22 15:09

nikssa23