Note that there are some explanatory texts on larger screens.

plurals
  1. POHow add active state to my menu with php or jquery or css?
    primarykey
    data
    text
    <pre><code>&lt;div id="nav"&gt; &lt;ul&gt; &lt;li class="item"&gt;&lt;a href=""&gt;Home&lt;/a&gt;/&lt;/li&gt; &lt;li class="item"&gt;&lt;a href="two"&gt;Tab2&lt;/a&gt;&lt;/li&gt; &lt;li class="item"&gt;&lt;a href="three"&gt;Tab3&lt;/a&gt;&lt;/li&gt; &lt;li class="item"&gt;&lt;a href="four"&gt;Tab3&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div&gt; </code></pre> <p>now, i want to add class='active' to the menu. when the menu is the current page.namely. when i on the home page. the li label is <code>&lt;li class="item" class="active"&gt;</code> the others are &lt;<code>li class="item"&gt;</code>. when i on the Tab2 page. the li label is <code>&lt;li class="item" class="active"&gt;</code>.the others are <code>&lt;li class="item"&gt;</code></p> <p><strong>PS:</strong> IF I want to add the class="active" to a label, like this <code>&lt;li class="item"&gt;&lt;a href="" class="active"&gt;Home&lt;/a&gt;/&lt;/li&gt;</code>. how should i do? according to the <strong>Headshota's</strong> instruction. i got this, but it's too complicated. is there a simple way to get it with php? thank you.</p> <pre><code>&lt;?php $current = array("","two","three","four"); ?&gt; then &lt;li class="item"&gt;&lt;a href="" class="&lt;?php if($GET[$current(0)]=="") echo "active"; ?&gt;"&gt;Home&lt;/a&gt;/&lt;/li&gt; &lt;li class="item"&gt;&lt;a href="two" class="&lt;?php if($GET[$current[1]]=="two") echo "active"; ?&gt;"&gt;Tab2&lt;/a&gt;&lt;/li&gt; &lt;li class="item"&gt;&lt;a href="three" class="&lt;?php if($GET[$current[2]]=="three") echo "active"; ?&gt;"&gt;Tab3&lt;/a&gt;&lt;/li&gt; &lt;li class="item"&gt;&lt;a href="four" class="&lt;?php if($GET[$current[3]]=="four") echo "active"; ?&gt;"&gt;Tab3&lt;/a&gt;&lt;/li&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload