Adding And Removing Css Classes On Href
I have a page with 2 links on it. The page URL is example.com/all Now the 2 links on the page, one goes to example.com/all/list and the other to example.com/all/map What I want is
Solution 1:
this can be done at the server side.
You need to set the current link on the page.
like if you have static html page then this can be done as
page : example.com/all/list
<aclass="current"href="example.com/all/list"> All</a><ahref="example.com/all/map">Map</a>
page : example.com/all/map
<ahref="example.com/all/list"> All</a><aclass="current"href="example.com/all/map">Map</a>
I don't know much about PHP but you can also set this in PHP by checking the current page url.
Solution 2:
Here's a helper I use in PHP:
<?phpfunctioncurrent_class_if($condition) {
return$condition ? 'class="current"' : '';
}
?>
Then in the page logic:
<?php$page = 'list';
?><ahref="example.com/all/list"<?= current_class_if($page=='list') ?>> All </a><ahref="example.com/all/map"<?= current_class_if($page=='map') ?>> Map </a>
Post a Comment for "Adding And Removing Css Classes On Href"