Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: jQuery enquiry.

  1. #1
    New Coder
    Join Date
    Jul 2011
    Location
    London
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    jQuery enquiry.

    Hi,
    In my code below, I'm looking to select the title attribute when a button is clicked...but it doesn't seem to work...could anybody help me with this please?

    Code:
    <html>
      <head>
        <title></title>
        <script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
        <style type="text/css" title="content1">
          body {
            background: #ccc;
            color: #aaa;
            font: 12px courier new;
            line-height: 20px;        
          }
          button {
            background: #f1f1f1;
            border: 1px solid #aaa;
            color: #aaa;
            font: bold 11px arial;
            padding: 10px;
          }
        </style>
        
        <style type="text/css" title="content2">
          body {
            background: #f1f1f1;
            color: #aaa;
            font: 12px arial;
            line-height: 20px;
          }
          
          #wrap {
            background: #fff;
            border: 1px solid #ccc;
            margin: auto;
            padding: 10px;
          }
        </style>
    
        <script>
         $(document).ready( function(){
          $("button").click( function() {
            alert("you've clicked me!");
            if($('style').attr("title")=="content1") {
              $('style').attr("title", "content2");
            };
          });      
         });
         </script>
      </head>
      
      <body>
        <div id="wrap">
          <button>Click me!</button>
        </div>
      </body>  
    </html>

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,608
    Thanks
    11
    Thanked 619 Times in 599 Posts
    the code does exactly what you describe: changes the title attrib of the first style tag from content1 to content2...

    you you trying to disable and enable css chunks or something?
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com


  •  

    Posting Permissions

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