I would like to color the selected text in the site navigation.

Asked 1 years ago, Updated 1 years ago, 91 views

I'd like to change the character color of the selected page, which is common in site navigation.
What should I do?
For example, in the following case, after clicking the company guide, when the company guide page is displayed, the text of &li><a href="#">company guide<a></li>I would like to move like this.

<ul class="nav">
  <li><a href="#">Company Information</a></li>
  <li><a href="#">Product List</a></li>
  <li><a href="#">Contact Us</a></li>
</ul>

javascript html jquery css

2022-09-30 21:22

1 Answers

I think there is a way to read the page, but if you read it partially when you need it, such as ajax,
There is also a way to switch from click to click as follows.

//.active Class that represents the button on the page being displayed
$('.navli').on('click', function(){
  $('.active').removeClass('active');
  $(this).addClass('active');
});

Depending on the page you retrieve (such as the file name or information in the file), you can choose which elements you want to class.

The former one is easy, but the latter one is easy to handle how to switch pages, and there are many buttons on the same page, and when the conditions are met...

Also, if there are only a few html files and you want to load them all together, you can add a class such as active to each file and color them with it.


2022-09-30 21:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.