I
I
Ivan Promin2015-02-09 17:26:17
css
Ivan Promin, 2015-02-09 17:26:17

Highlight the active menu item, if the menu item contains a GET request?

There is a piece of code:

<ul id="msgText" class="shassi_menu_top">
  <a class="act" href="/katalog_spectehniki/kranymanipulyatory/gaz/"><li>
  ГАЗ
</li></a>
<a href="/katalog_spectehniki/kranymanipulyatory/kamaz/"><li>
  КАМАЗ
</li></a>
</ul>


And a piece of the script, while when the user is on a page with a url that is equal to the link, then the class "act," is assigned, but when the filter is used,
.../gaz/?fields_filter%5Bmodel_avtomobilya,
then the class is not assigned.

<script type="text/javascript">
try{
var el=document.getElementById('msgText').getElementsByTagName('a');
var url=document.location.href;

for(var i=0;i<el.length; i++){
if (url==el[i].href) {
el[i].className += ' act';
};
};
}catch(e){}

</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg, 2015-02-09
@sweetcode

document.location.href;
replaced by
document.location.pathname+'/';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question