Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Adding Stylesheets

How to add a stylesheet when a particular radio button is clicked.I trie to add below but it's not working any alternative please help...

Here's my code: <script language="JavaScript"> function colors(col) { switch(col) { case 'premium': document.getElementById("s").href= 'style2.css'; break; case 'classic': document.getElementById('s').href= 'c.css'; break; } } </script> <form name=”form1” method="post" action="new1.php"> <label> <input type="radio" name=”style” id="s" value=”radio” onClick="colors('premium')"> premium</label> <label> <input type="radio" name=”style” id="s" value=”radio” onClick="colors('classic')">

classic</label>

</form>

4 Answers

Something like this should do it

$('.button').click(function (){
   $('link[href*=".css"]').attr('href','styles1.css');
});
$('.button2').click(function (){
   $('link[href*=".css"]').attr('href','styles2.css');
});

So basically it will look for any link with href ending .css (you can be more specific to avoid grid sheets and normalize) then it will change to styles1 or 2 depending on which button you click.

Even the above code is not working..

Put what you have into a codepen.io pen and i will have a look for you

KARTHIK K S I need to see your HTML also. It is easier to put it on codepen.io and free then i can investigate the problem.

Here's my code: <script> $(document).ready(function(){ $('.button').click(function (){ $('link[href*=".css"]').attr('href','style.css'); }); $('.button2').click(function (){ $('link[href*=".css"]').attr('href','c.css'); }); }): </script> <form name=”form1” method="post" action="new1.php"> <label> <input type="radio" name=”style” class="button" value=”radio” > premium</label> <label> <input type="radio" name=”style” class="button2" value=”radio” >

classic</label> </form>

i'm really sorry and here is my complete code: <html> <head> <script> $(document).ready(function(){ $('.button').click(function (){ $('link[href*=".css"]').attr('href','style.css'); }); $('.button2').click(function (){ $('link[href*=".css"]').attr('href','c.css'); }); }): </script> </head> <body> <hr> <form name=”form1” method="post" action="new1.php"> <label> <input type="radio" name=”style” class="button" value=”radio” > premium</label> <label> <input type="radio" name=”style” class="button2" value=”radio” >

classic</label> </form> <hr></hr> </body></html> <?php

$rname=$_GET['username']; $db = new PDO("mysql:host=localhost;dbname=resumedb;port=3306","root","root"); if(! $db ) { die('Could not connect: ' . mysql_error()); } try { $sql = "SELECT * FROM tblresume where Name='$rname'"; echo "<h3> ResumeDetails </h3>"; echo"<html>"; echo"<head>";

echo "</head>"; echo "</html>"; foreach ($db->query($sql) as $row) { echo "<h4 class='s1'>"."PersonalDetails"."</h4>"; echo "<div class='s2'>". "Name:" .$row['Name']."<br>" ; echo "DOB:".$row['DOB']."<br>" ; echo "Address1:".$row['Address1']."<br>" ; echo "Address2:".$row['Address2']."<br>" ; echo "city:".$row['city']."<br>" ; echo "Pin:".$row['PIN'] ."<br>"; echo "country:".$row['country'] ."<br>"; echo "contactnumber".$row['contactnumber']."<br>" ; echo "EmailId:".$row['EmailId']."<br>"; echo "</div>"; echo "<h4 class='s7'>"."Summary"."</h4>"; echo "<div class='s8'>". $row['Summary'] . "</td>"; echo "</div>"; echo "<h4 class='s3'>"."Education"."</h4>"; echo "<div class='s4'>"."Degree:" .$row['HighestEducation'] ."<br>" ; echo "College:".$row['Institute'] ."<br>" ; echo "</div>"; echo "<h4 class='s5'>"."WorkSummary"."</h4>"; echo $row['TotalWorkExperience'] . "</td>"; echo "<div class='s6'>"."ReferenceCheck:".$row['LastEmployerName']."<br>"; echo "EmploymentDetails:".$row['LastEmploymentDetails']."<br>" ; echo "No of years employed".$row['LastEmploymentYears']."<br>" ; echo "</div>"; }

}

catch(PDOException $e) { echo $e->getMessage(); }

?>