SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question jQuery not working

    Hi - I have snippet of code (pasted below) and although the html/css is rendering but for some reason the jQuery is not doing anything.
    I can't see what is wrong after spending a while trying to figure it out, any help would be appreciated.

    HTML Code:
    <!DOCTYPE html>
    
    <html lang="en">
    <head>
      <title>Introduction</title>
      <style>
      /*
         CSS Style sheets are only inline to keep the
         code examples together for readability. When
         using this code in production, please
         externalize all style sheets.
      */
      .myclass {
        background-color: black;
        color: white;
      }
      </style>
     </head>
    <body>
    <h1>Introduction</h1>
    
    <p>The HTML in the examples is kept as simple as
      possible.</p>
    
    <p class="myclass">This is a placeholder for content</p>
    
    <p id="myid">You can click on this paragraph</p>
    
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    
    <script type="text/javascript">
    // JavaScripts are only inline to keep the code
    // examples together for readability. When using
    // this code in production, please externalize
    // all JavaScript code.
    
    $(document).ready(function() {
    
      $('p').css('font-weight', 'bold');
    
      $('.myclass').html('Different <em>content</em>');
    
      $('#myid').click(function() {
        alert('Hello world!');
      }
    });
    
    </script>
    
    </body>
    </html>


    .

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,331
    Mentioned
    463 Post(s)
    Tagged
    8 Thread(s)
    There's a little syntax error near the end of your script. Add the bit in red:

    Code:
    $(document).ready(function() {
    
      $('p').css('font-weight', 'bold');
    
      $('.myclass').html('Different <em>content</em>');
    
      $('#myid').click(function() {
        alert('Hello world!');
      });
    });

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, I must have been day dreaming


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •