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


target pseudo class question (advanced selectors)

I think I might find this very useful in the future. just one problem. How might i make it possible for the page to return to normal? Right now once you've clicked a target, the only way to un-highlight it's paragraph is by highlighting another. Is there a way to click the target a second time to un-highlight it?


2 Answers

Andrew Shook
Andrew Shook
31,709 Points

I don't believe there is a way to undo css applied by the :target pseudo selector. You might be able to do something similar using jQuery and Javascript, but you would run into the same issue of how to tell the browser when to undo the css changes. Something like this might work:

$("nav a").bind("click", function(click){ 
    //stop the page from autoscrolling to the select element
     //variable that changes the clicked link's href into an ID
     var target = "#"+$(this).attr("href");
     //hold this distance from the top that the element with ID target is located
     var position = $(target).offset();
     //scrolls the page to the selected element
     $(body).animate({scrollTop : position.top}, 600);
     //add class to the element to apply css
     //creates a temporary click event for the body to undo the "target" css
 $("body *").bind("click", function(){
            highlight = false;
                    //unbind temporary click assigned to all body element to undo "target" css
                    $(" body *").unbind("click");

This code might need some tweaking, but it should work for the most part. I know this ins't exactly what you asked for but its the only way I know to do what you want to do. Hope this helps.

I'm not sure what your reffering to, but if what your clicking on turn's purple after you click on it try giving it some styles like a color value.

I was referring to the :target pseudo class