Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: styling javascript element  (Read 3728 times)

0 Members and 1 Guest are viewing this topic.

babybird

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Unknown
    styling javascript element
    « on: June 22, 2012, 11:36:09 AM »
    Hi there! I'm using a random quote script I found here on computer hope.
    http://www.computerhope.com/j15.htm

    I have been able to style the quotes, but i would like to give one style to quotes and another one to authors, any clue how can i do that?

    Thank you! i appreciate any help

    kpac

    • Web moderator
    • Moderator


    • Hacker

    • kpac®
    • Thanked: 184
      • Yes
      • Yes
      • Yes
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 7
    Re: styling javascript element
    « Reply #1 on: June 24, 2012, 10:53:46 AM »
    There're a few errors in that code actually.

    Fixed:
    Code: [Select]
    <script type="text/javascript">
    //store the quotations in arrays
    quotes = [];
    authors = [];
    quotes[0] = "I have a new philosophy. I'm only going to dread one day at a time.";
    authors[0] = "Charles Schulz";
    quotes[1] = "Reality is the leading cause of stress for those in touch with it.";
    authors[1] = "Jack Wagner";
    quotes[2] = "Few things are harder to put up with than the annoyance of a good example.";
    authors[2] = "Mark Twain";
    quotes[3] = "The pure and simple truth is rarely pure and never simple.";
    authors[3] = "Oscar Wilde";
    quotes[4] = "There's no business like show business, but there are several businesses like accounting.";
    authors[4] = "David Letterman";
    quotes[5] = "Man invented language to satisfy his deep need to complain.";
    authors[5] = "Lily Tomlin";

    //calculate a random index
    index = Math.floor(Math.random() * quotes.length);

    //display the quotation
    document.write("<dl>\n");
    document.write("<dt>" + "\"" + quotes[index] + "\"</dt>\n");
    document.write("<dd>" + "-- " + authors[index] + "</dd>\n");
    document.write("</dl>\n");

    //done
    </script>

    To change the styling all you have to do is style the DD and DT elements seperately, DD being the author.