Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-19-2011, 10:11 AM   PM User | #1
sho88
New Coder

 
Join Date: Jul 2011
Location: London
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
sho88 is an unknown quantity at this point
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>
sho88 is offline   Reply With Quote
Old 07-19-2011, 05:51 PM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:56 PM.


Advertisement
Log in to turn off these ads.