Simple jquery questions

Discussion in 'jQuery' started by Notting, Sep 11, 2010.

  1. #1
    I am trying to implement the example from the jquery homepage. I have:

    http://www.mytroutfishingtips.com/archive/test11.php

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
        <head>
            <meta http-equiv="content-type" content="text/html; charset=utf-8" />
            <link rel="stylesheet" href="../effect.css" type="text/css" />
            <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
            <script type="text/javascript" src="http://static.jquery.com/files/rocker/scripts/custom.js"></script>
    
        </head>
        <body>
                    <div id="jq-learnjQuery" class="jq-clearfix">
                        <div id="jq-learnNow">
                            <div class="jq-codeDemo jq-clearfix">
                                <code>$("p.neat").addClass("ohmy").show("slow");</code>
                                <a href="http://docs.jquery.com/Tutorials" class="jq-runCode">Run Code</a>
                                <p class="neat"><strong>Congratulations!</strong> You just ran a snippet of jQuery code. Wasn't that easy? There's lots of example code throughout the <strong><a href="http://docs.jquery.com/">documentation</a></strong> on this site. Be sure to give all the code a test run to see what happens.</p>
                            </div>
                        </div>
                    </div>
        </body>
    </html>
    
    Code (markup):
    How do I amend the code so that "$("p.neat").addClass("ohmy").show("slow");" is not outputted to the pages but the code still works?

    Many thanks
    Notting
     
    Notting, Sep 11, 2010 IP
  2. tdemetri

    tdemetri Peon

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    omit or comment out this line:

     <code>$("p.neat").addClass("ohmy").show("slow");</code>
    
    Code (markup):
     
    tdemetri, Sep 11, 2010 IP
  3. Notting

    Notting Notable Member

    Messages:
    3,210
    Likes Received:
    335
    Best Answers:
    0
    Trophy Points:
    280
    #3
    If you take that line out then the code does not work. :(

    Notting
     
    Notting, Sep 11, 2010 IP
  4. tdemetri

    tdemetri Peon

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ok- i didn't even try to see what the function was doing, just tried to eliminate the document from writing that line of code.

    you could of course change that line of code to:
    <span id="inv"> <code>$("p.neat").addClass("ohmy").show("slow");</code></span>
    Code (markup):
    which of course means that you need to add this css rule:

     #inv {display:none;}
    Code (markup):
    and then it will never show. if you need that line to be there before the click but not afterwards, change the JQ function to reflect that.
     
    tdemetri, Sep 11, 2010 IP
  5. Riverofrhyme

    Riverofrhyme Peon

    Messages:
    137
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Are you trying to run the code? It need's script tags then.
     
    Riverofrhyme, Sep 12, 2010 IP
  6. HungryMinds

    HungryMinds Active Member

    Messages:
    216
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    63
    #6
    <script>$("p.neat").addClass("ohmy").show("slow");</script>
     
    HungryMinds, Sep 12, 2010 IP