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,184
    Thanks
    10
    Thanked 569 Times in 550 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?
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5


  •  

    Posting Permissions

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