Home Web Front-end JS Tutorial Js implements the current click on the a label to change color and highlight other a labels to return to the original color_javascript skills

Js implements the current click on the a label to change color and highlight other a labels to return to the original color_javascript skills

May 16, 2016 pm 05:12 PM
a tag Discoloration Click

When a page has multiple a tags, and when clicked, it will jump to the current page. How can the clicked tag change color and be highlighted, and other tags return to their original colors?

Use JS to achieve:

Assume the current page is "1.aspx"

1. Set the value of a tag ID:

Copy code The code is as follows:

""
""
""

2. Write JS method:
Copy code The code is as follows:

<script> <br>&(document).ready (function(){ <br>var id = windows.ulr.substring(windows.ulr.IndeOf("?id="),1) //Get the id value<br>var currtA = document.getElementById(id); //Get the currently clicked a tag <br>if(currtA != null) <br>currtA.style.color = "#f00"; <br>}); <br></script>

For other situations, such as clicking the a tag page without jumping, you can write like this:
Copy code Code As follows:

""

<script> <br>function changeCss(obj){ <br>var alist = document.getElementsByTagName("a"); <br>for(var i =0;i < alist.Length;i ){ <br>alist[i].style. color = "#000"; //Assign primary color to all a tags<br>} <br>obj.style.color = "#f00"; //Highlight the current tag<br>} <br>//Of course You can also use Jquery's $("a").removeCss() and addCss() to achieve <br></script>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What file is index.html? What file is index.html? Feb 19, 2024 pm 01:36 PM

index.html represents the home page file of the web page and is the default page of the website. When a user visits a website, the index.html page is usually loaded first. HTML (HypertextMarkupLanguage) is a markup language used to create web pages, and index.html is also an HTML file. It contains the structure and content of a web page, as well as tags and elements used for formatting and layout. Here is an example index.html code: &lt

How to set multiple timers on iPhone iOS 17 How to set multiple timers on iPhone iOS 17 Sep 18, 2023 am 09:01 AM

In iOS 17, you can set multiple timers on your iPhone using the Clock app, or use Siri to set it hands-free. We discuss both in this article. Let's take a look at them. Set Multiple Timers on iPhone Using the Clock App Open the Clock app on your iPhone and tap the Timers tab in the lower right corner. Now, set the hours, minutes, and seconds. You can use the "Label" and "When does the timer end" options to set a name for the timer and a preferred tone when the timer completes. This will help you differentiate between timers. Once done, click the "Start" button. Then, click the "+" icon in the upper right corner. Now, repeat the above steps to set multiple timers on iPhone. You can also browse

How to remove the color of a tag in css How to remove the color of a tag in css Apr 25, 2024 pm 05:42 PM

To remove the inherent color of the a tag, you can use the following method: Use the CSS color property to specify the text color. Use the CSS link-color property to specify link color. Use the CSS text-decoration property to remove underline and default text color. Use the CSS hover color property to change the text color on mouseover. Use the CSS visited color property to change the text color of visited a tags.

What is the keyboard shortcut for switching to black and white mode in win10? What is the keyboard shortcut for switching to black and white mode in win10? Jan 10, 2024 pm 01:26 PM

The win10 system launched by Microsoft has many new features compared to previous versions. For example, you can use the color filter, which is the color filter shortcut, to change the overall display of win10 to black and white. Some friends may not know how to set up this effect. So let me tell you now. Hope it helps you~ What is the solution to the shortcut key to change win10 to black and white? 1. You can use the shortcut ++ to turn on or off the color filter. 2. If you want to completely turn off the color filter, you can right-click the start logo on the taskbar. Select option 3 in the pop-up menu. Select option 4 in the opened interface. Select option 5 using the easy bar on the left side of the opened page. In the color filter interface on the right side of the opened page we will see a

How to Make a Shopping List in the iOS 17 Reminders App on iPhone How to Make a Shopping List in the iOS 17 Reminders App on iPhone Sep 21, 2023 pm 06:41 PM

How to Make a GroceryList on iPhone in iOS17 Creating a GroceryList in the Reminders app is very simple. You just add a list and populate it with your items. The app automatically sorts your items into categories, and you can even work with your partner or flat partner to make a list of what you need to buy from the store. Here are the full steps to do this: Step 1: Turn on iCloud Reminders As strange as it sounds, Apple says you need to enable reminders from iCloud to create a GroceryList on iOS17. Here are the steps for it: Go to the Settings app on your iPhone and tap [your name]. Next, select i

How to set up my business card in Contacts on iPhone [2023] How to set up my business card in Contacts on iPhone [2023] Sep 22, 2023 pm 09:17 PM

With My Business Cards in iOS, you can create a personalized contact card that Siri and other services recognize and associate with you and your phone number. With the introduction of contact posters in iOS17, My Cards becomes very important as it is now used to create your contact posters. If you're eager to get your contact poster up and running, you have to start by setting up My Business Card. We'll walk through how to create a My Business Card and how to make it work smoothly with Siri and your contact poster. How to Set Up My Business Cards in Contacts on iPhone [2023] If you are setting up My Business Cards on your iPhone for the first time, you must do it through the Contacts app only

How to jump to another page using a tag How to jump to another page using a tag Sep 11, 2023 pm 04:01 PM

a tag to create a hyperlink, and then through the a tag, you can link one page to another page. Detailed introduction: To achieve page jump, you need to fill in the URL of the target page into the href attribute. The URL can be a relative path or an absolute path. The relative path is the path relative to the current page, and the absolute path is the complete URL. address.

How to turn off alarms on iPhone [2023] How to turn off alarms on iPhone [2023] Aug 21, 2023 pm 01:25 PM

Since the advent of smartphones, they have undoubtedly replaced alarm clocks. If you own an iPhone, you can use the Clock app to easily set as many alarms for multiple occasions throughout the day. The app lets you configure the alarm time, the tone, how often it repeats, and whether you want to delay them using the Snooze option. If you want to turn off the alarm you have set, the following post should help you disable and delete regular alarms and wake-up alarms on your iPhone. How to Turn Off a Regular Alarm on iPhone By default, when you add an alarm on the Clock app or ask Siri to add an alarm for you, you're actually creating a regular alarm. You can create as many alarm clocks on your iPhone as you like and put them

See all articles