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

PHP

{ echo "on";}

In the video Adding Active States to the Navigation, he had echo "on" to make the link underlined. Why would it underline the link rather than display the work "on"?

_Randall

4 Answers

Caleb McElroy
PLUS
Caleb McElroy
Courses Plus Student 12,953 Points

Hello Randall,

    <ul class="nav">
        <li class="shirts <?php if ($section == "shirts") { echo "on"; } ?>"><a href="shirts.php">Shirts</a></li>
        <li class="contact <?php if ($section == "contact") { echo "on"; } ?>"><a href="contact.php">Contact</a></li>
        <li class="cart"><a href="#">Shopping Cart</a></li>
    </ul>

Above is the code you are talking about, correct?

    <li class="contact <?php if ($section == "contact") { echo "on"; } ?>">

In this code, "on" is being echoed as a class. So if to were to right the html this php would produce it would be:

     <li class="contact on">

Therefore not echoing "on" to the screen but echoing "on" to the class, which creates the above.

Hopefully this helps.

Does the "on" in this case as it related to the class mean underline or it means make whatever the class is set up as to be displayed which in this case is to make the link underlined?

_Randall

James Barnett
James Barnett
39,199 Points

If you are wondering about how the CSS works behind the scenes you can check out the Build a Simple Website course.

Caleb McElroy
PLUS
Caleb McElroy
Courses Plus Student 12,953 Points

Exactly, the "on" class calls a particular set of CSS, which in this case make the links underlined.

Thanks Caleb! :)

_Randall