skip to Main Content

I am trying to change a HTML document’s CSS properties using an external jQuery Script.
The jquery is supposed to change all paragraphs with the class given to it.

I am not allowed to change the HTML document.

I wrote the jquery in the HTML Document first and it worked fine. Now I need to put in an external file, but I think I am doing something wrong.

I am not allowed to link to the latest version of Jquery calling it in the HTML file.
How do I call it from my external file?
Is that Possible?

Please see my code below and thank you!!


<html>
    <head>
        <title>comp1911 final exam part 2 #3</title>

        <script type="text/javascript" src="question3.js"></script>

    </head>
<body>

<p class="sports"> 1. At the age of 10, Gretzky scores 378 goals in Brantford's atom league - still an age group record.

Circa 1968 - Wayne dominated the Brantford atom league, scoring 378 goals.

2. While playing in the prestigious International Pee Wee Hockey Tournament in Quebec City's Le Colisee, the 14-year-old Gretzky is frequently besieged by autograph seekers.

3. As a teenager, young Wayne often competes against players much older. At 14 he plays in Tier II junior and major junior at 15.

4. Wayne first dons his now famous No. 99 jersey as a member of the Sault Ste. Marie Greyhounds. Originally wanting to wear No. 9 like his idol Gordie Howe, Gretzky settles on his trademark number after wearing No. 19 for a few weeks

5. In May 1978, Gretzky turns pro at 17 with the Indianapolis Racers of the World Hockey Association.

6. The financially strapped Indianapolis franchise trades Gretzky to the Edmonton Oilers of the WHA in May of 1978.

7. In his first season with the Oilers, Gretzky registers 46 goals and 110 points on his way to capturing WHA rookie of the year honors.</p>
<p class="books">Nikolai Vasilievich Gogol was a Ukrainian-born Russian  novelist, humourist, and dramatist.[2]

He is considered the father of modern Russian realism. His early works, such as Evenings on a Farm Near Dikanka, were heavily influenced by his Ukrainian upbringing and identity.[3][4] His more mature writing satirised the corrupt bureaucracy of the Russian Empire, leading to his exile. On his return, he immersed himself in the Orthodox Church.[5] The novels Taras Bul'ba (1835; 1842 [revised edition]) and Dead Souls (1842), the play The Inspector-General (1836, 1842), and the short stories Diary of a Madman, The Nose and The Overcoat (1842) are among his best known works. With their scrupulous and scathing realism, ethical criticism as well as philosophical depth, they remain some of the most important works of world literature.</p>
<p class="comedy">Jack Handey (born 25 February 1949) is an American  humorist. He is best known for his Deep Thoughts by Jack Handey, a large body of surrealistic  one-liner jokes, as well as his "Fuzzy Memories" and "My Big Thick Novel" shorts. Although many people assume otherwise,[1][2]  Handey is a real person, not a pen name or a character.</p>
<p class="sports books comedy">I found this book: http://www.amazon.com/Teed-Off-Laughs-Greens-Sports/dp/0233995005/ref=sr_1_1?ie=UTF8&s=books&qid=1277749796&sr=1-1 You don't have to be good to play, but a low level of self-esteem is helpful! Humorous collection of colour photographs and hilarious text reduces our heroes of the golf course to mere mortals. No golfing disaster is left secret and the 80 photographs only go to prove the fallibility of international stars.</p>
<p class="life">To my dearest daughter,

Now that you are ten, I want to write to you about something that is important to me. Have you ever wondered how we know the things that we know? How do we know, for instance, that the stars, which look like tiny pinpricks in the sky, are really huge balls of fire like the Sun and very far away? And how do we know that the Earth is a smaller ball whirling round one of those stars, the Sun?
The answer to these questions is ‘evidence’.

Sometimes evidence means actually seeing (or hearing, feeling, smelling….) that something is true. Astronauts have traveled far enough from the Earth to see with their own eyes that it is round. Sometimes our eyes need help. The ‘evening star’ looks like a bright twinkle in the sky but with a telescope you can see that it is a beautiful ball – the planet we call Venus. Something that you learn by direct seeing (or hearing or feeling…) is called an observation.

Often evidence isn’t just observation on its own, but observation always lies at the back of it. If there’s been a murder, often nobody (except the murderer and the dead person!) actually observed it. But detectives can gather together lots of other observations which may all point towards a particular suspect. If a person’s fingerprints match those found on a dagger, this is evidence that he touched it. It doesn’t prove that he did the murder, but it can help when it’s joined up with lots of other evidence. Sometimes a detective can think about a whole lot of observations and suddenly realize that they all fall into place and make sense if so-and-so did the murder.</p>

<p class="books life">SIMPLIFY YOUR LIFE: 100 WAYS TO SLOW DOWN AND ENJOY THE THINGS THAT REALLY MATTER [Paperback]
Elaine St. James
Elaine St. James (Author)
› Visit Amazon's Elaine St. James Page
Find all the books, read about the author, and more.
See search results for this author
Are you an author? Learn about Author Central
(Author) For everyone who is overwhelmed by the increasing demands in their lives, here is the ideal guide for slowing down and finding peace of mind. In separate chapters covering career, household, health, social, finance, and personal affairs, this thought-provoking book offers one hundred proven, practical steps for creating a simple but elegant lifestyle. </p>
<p class="comedy books">Our Front Pages: 21 Years of Greatness, Virtue, and Moral Rectitude from America's Finest News Source (Onion Presents): Since its founding by a bloodthirsty tyrant in 1756, The Onion has not merely changed the way we think about the news -- it has changed whether we think about the news at all. As the first decade of this new millennium draws to a close, Our Front Pages shows us the first thing that presidents, kings, prime ministers, and popes saw when they opened their eyes each morning for the last 21 years. Now you, the common reader and citizen, can see what they saw and be as informed as they were with this important retrospective of the past two decades. You, too, will realize what generations before have realized and generations yet unborn will some day realize in turn: The Onion is not merely the chronicle of America. The Onion is America. </p>
<p class="life">Richard Feynman: Some years ago I had a conversation with a layman about flying saucers — because I am scientific I know all about flying saucers! I said "I don't think there are flying saucers'. So my antagonist said, "Is it impossible that there are flying saucers? Can you prove that it's impossible?" "No", I said, "I can't prove it's impossible. It's just very unlikely". At that he said, "You are very unscientific. If you can't prove it impossible then how can you say that it's unlikely?" But that is the way that is scientific. It is scientific only to say what is more likely and what less likely, and not to be proving all the time the possible and impossible. To define what I mean, I might have said to him, "Listen, I mean that from my knowledge of the world that I see around me, I think that it is much more likely that the reports of flying saucers are the results of the known irrational characteristics of terrestrial intelligence than of the unknown rational efforts of extra-terrestrial intelligence." It is just more likely. That is all.

* The Character of Physical Law. Cornell University Messenger Lectures (1964)
</p>
<p class="sports books life">Tiger Woods' father Earl Woods wrote "Training a Tiger: A Father's Guide to Raising a Winner in Both Golf and Life". The first thing you'll learn in this book, which details how Earl Woods raised his son, Tiger, to become probably the greatest golfer who ever lived, is that your child will never be another Tiger Woods. Tiger is a prodigy in the sense that Mozart was a prodigy. But even if your child has completely ordinary abilities, Training a Tiger shows how to pass on your love for a sport to your child. Most of the book is specific to golf, but the same lessons can be applied to any activity. </p>
<p class="sports">Ice hockey (hockey in countries where it is the most popular form of hockey) is a team sport played on ice, in which skaters use sticks to direct a puck into the opposing team's goal. It is a fast-paced physical sport. Ice hockey is most popular in areas that are sufficiently cold for natural reliable seasonal ice cover, such as Canada, the Czech Republic, Latvia, the Nordic countries (especially Sweden and Finland), the northern United States, Russia, Slovakia, and Switzerland. With the advent of indoor artificial ice rinks it has become a year-round pastime in these areas. Ice hockey is one of the four major North American professional sports. Worldwide the National Hockey League (NHL) is the highest level for men and both the Canadian Women's Hockey League  (CWHL) and the Western Women's Hockey League (WWHL) are the highest levels for women. It is the official national winter sport of Canada, where the game enjoys immense popularity.

While there are 68 total members of the International Ice Hockey Federation (IIHF), 162 of 177 medals at the IIHF World Championships have been taken by seven nations: Canada, the Czech Republic, Finland, Russia, Slovakia, Sweden and the United States.[1][2] Of the 64 medals awarded in men's competition at the Olympic level from 1920 on, only six did not go to the one of those countries. All twelve Olympic and 36 IIHF World Women Championships medals have gone to one of those seven countries, and every gold medal in both competitions has been won by either Canada or the United States</p>

$(“.sports”).css({“border”:”solid”});
$(“.sports”).css({“borderColor”:”green”})

            $(".life").css({"color":"red"})

            $(".books").css({"text-align":"right"})

            $(".comedy").css({"font-size":"200%"})

REVISED External Script:

$(".sports").css({"border":"solid"});
$(".sports").css({"borderColor":"green"})

$(".life").css({"color":"red"})

$(".books").css({"text-align":"right"})

$(".comedy").css({"font-size":"200%"})

2

Answers


  1. Instead of actually calling jQuery from your external JS file, you could just copy-paste the entire thing (minified, of course). The minified version of 1.9.1 can be found here. Just make sure to paste it at the very top of your external file, so that all of your code that utilizes jQuery comes after.

    Login or Signup to reply.
  2. jsFiddle Demo

    Why use jquery? You can do this with a combination of iteration, built in functionality, and getElementsByClassName.

    js

    window.onload = function(){
     var sports = document.getElementsByClassName("sports");
     for( var i = 0; i < sports.length; i++ ){
      sports[i].style.border = "solid";     
      sports[i].style.borderColor = "green";     
     }
     var life = document.getElementsByClassName("life");
     for( var i = 0; i < life.length; i++ ){
      life[i].style.color = "red";     
     }
     var books = document.getElementsByClassName("books");
     for( var i = 0; i < books.length; i++ ){
      books[i].style.textAlign = "right";     
     }
    
     var comedy = document.getElementsByClassName("comedy");
     for( var i = 0; i < comedy.length; i++ ){
      comedy[i].style.fontSize = "200%";     
     }
    };
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search