Simple jQuery with HTML

Simple jQuery with HTML
0.0 0

#1

I am working on the very basic front end development project and trying things out but some of the jQuery classes I am trying to add are not working. I am not sure where I am going wrong or if I am not understanding something but any help would be appreciated.
HTML

<!DOCTYPE html>
<html>
  <head>
    <title>Tribute</title>
    <meta charset="UTF-8">
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
    <link rel="stylesheet" type="text/css" href="./index3.css">
    <script src="./index.js"></script>
  </head>
  <body>
    <div id="main" class="container" style="background-color: #D3D3D3">
      <nav>
        <ul class="nav nav-pills justify-content-center">
          <li class="nav-item"><a class="nav-link" href="./index1.html">HTML &amp; CSS</a></li>
          <li class="nav-item"><a class="nav-link" href="./index2.html">HTML &amp; Bootstrap</a></li>
          <li class="nav-item"><a class="nav-link" href="./index3.html">HTML, Bootstrap &amp; jQuery</a></li>
        </ul>
      </nav>
      <header class="jumbotron text-center" style="background-color: inherit;">
          <h1>Dr. Norman Borlaug</h1>
          <em>The man who saved a billion lives</em>
      </header>
      <figure class="img-thumbnail">
          <img src="https://c2.staticflickr.com/4/3689/10613180113_fdf7bcd316_b.jpg" alt="Photo of Dr. Borlaug in a wheat field with other biologists." style="width: 100%;">
          <figcaption class="text-center"><small>Dr. Norman Borlaug, third from left, trains biologists in Mexico on how to increase wheat yields - part of his life-long war on hunger.</small></figcaption>
      </figure>
      <div>
          <p>Here's a time line of Dr. Borlaug's life:</p>
          <ul>
              <li><b>1914</b> - Born in Cresco, Iowa</li>
              <li><b>1933</b> - Leaves his family's farm to attend the University of Minnesota, thanks to a Depression era program known as the "National Youth Administration"</li>
              <li><b>1935</b> - Has to stop school and save up more money. Works in the Civilian Conservation Corps, helping starving Americans. "I saw how food changed them", he said. "All of this left scars on me."</li>
              <li><b>1937</b> - Finishes university and takes a job in the US Forestry Service</li>
              <li><b>1938</b> - Marries wife of 69 years Margret Gibson. Gets laid off due to budget cuts. Inspired by Elvin Charles Stakman, he returns to school study under Stakman, who teaches him about breeding pest-resistent plants.</li>
              <li><b>1941</b> - Tries to enroll in the military after the Pearl Harbor attack, but is rejected. Instead, the military asked his lab to work on waterproof glue, DDT to control malaria, disenfectants, and other applied science.</li>
              <li><b>1942</b> - Receives a Ph.D. in Genetics and Plant Pathology</li>
              <li><b>1944</b> - Rejects a 100% salary increase from Dupont, leaves behind his pregnant wife, and flies to Mexico to head a new plant pathology program. Over the next 16 years, his team breeds 6,000 different strains of disease resistent wheat - including different varieties for each major climate on Earth.</li>
              <li><b>1945</b> - Discovers a way to grown wheat twice each season, doubling wheat yields</li>
              <li><b>1953</b> - crosses a short, sturdy dwarf breed of wheat with a high-yeidling American breed, creating a strain that responds well to fertalizer. It goes on to provide 95% of Mexico's wheat.</li>
              <li><b>1962</b> - Visits Delhi and brings his high-yielding strains of wheat to the Indian subcontinent in time to help mitigate mass starvation due to a rapidly expanding population.</li>
              <li><b>1970</b> - receives the Nobel Peace Prize</li>
              <li><b>1983</b> - helps seven African countries dramatically increase their maize and sorghum yields</li>
              <li><b>1984</b> - becomes a distinguished professor at Texas A&amp;M University</li>
              <li><b>2005</b> - states "we will have to double the world food supply by 2050." Argues that genetically modified crops are the only way we can meet the demand, as we run out of arable land. Says that GM crops are not inherently dangerous because "we've been genetically modifying plants and animals for a long time. Long before we called it science, people were selecting the best breeds."</li>
              <li><b>2009</b> - dies at the age of 95.</li>
            </ul>
      </div>
      <blockquote class="blockquote">
          <p>Borlaug's life and achievement are testimony to the far-reaching contribution that one man's towering intellect, persistence and scientific vision can make to human peace and progress.</p>
          <footer class="blockquote-footer"><cite>Indian Prime Minister Manmohan Singh</cite></footer>
      </blockquote>
      <div>
          <p>If you have time, you should read more about this incredible human being on his <a href="https://en.wikipedia.org/wiki/Norman_Borlaug">Wikipedia</a> entry.</p>
      </div>
    </div>
    <footer class="text-center"><small>Written and Coded by Ali Hamza.</small></footer>
  </body>
</html>

JS

$(document).ready(function() {
  //Testing to see if files have been linked properly and CDN is functional.
  $("body").css("background-color", "black");
  // Not functioning.
  $("#main").addClass("animated bounce");
});

I have tried multiple selectors for element, class and id’s with multiple combinations such as fadeIn, slideIn etc but none of them seem to do anything to the page. Changing the background color worked however indicating that the script link for the CDN and my .js file are working.


#2

Are you seeing any errors in the browser’s console (Ctrl+Shft+J in Chrome)?


#3

Where do you have the class “animated bounce”? Because if you inspect elements you can see the jquery works fine the class is added.
If you want to use quick animation classes you can use animate.css. Just add this in your head tag:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css">

That’s the CDN or else you can just download the CSS from Animate.css.


#4

Thanks you. Inspecting the developer console and just the Inspect element in general was good guide on where to start.


#5

The classes were indeed being added but there was no Animate.css CDN to get those classes from somewhere. I was assuming that when I link to the jQuery CDN it comes with those classes as the lessons suggested (vaguely if anything.) Also again, looking at the browsers developer console would have helped me to start looking in the right place. Much appreciated!


#6

More info on animating with jquery - > jQuery W3 schools.