CSS for dynamic styling of anchor tags

On the example.com website, I have added the following HTML (Very important note). Now, I am attempting to add CSS to a selected link in order to highlight the chosen value.

<a class="value" href="http://example.com?filter=value1">Value1
<a class="value" href="http://example.com?filter=value2">Value2 etc

Essentially, I want to apply CSS to the selected anchor tag after it loads example.com?filter=value1.

PLEASE NOTE: .value:selected{color:blue} does not work as the link refreshes the page.

Answer №1

If you're looking to emphasize certain elements on a webpage, you can use the following code to check if the URL contains a specific string and then apply custom CSS accordingly.

if(document.location.href.match(/\?filter=value1/)){
   // Add custom css to element
}

For instance, this snippet will change the color of a link only when the user lands on the page through that particular link:

if(document.location.href.match(/\?filter=value1/)){
       $('a[href="http://example.com?filter=value1"]').css('color', 'blue');
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips on anchoring a footer to the bottom of a webpage following a loop in PHP

After running a PHP file with some HTML, I noticed that the footer is not staying at the bottom of the page as intended. It seems to be overlapping with the products or leaving empty space after them due to changes in the DOM. If anyone has insight on how ...

The Jquery append() method seems to be having issues specifically in the Internet Explorer

I am a jQuery 1.10.2 version with the task of inserting an XML node at a specific location within an existing XML structure. To achieve this, I am utilizing the jQuery `append()` function successfully in Chrome, Firefox, and IE Edge; however, it is encount ...

"Encountering issues while trying to invoke controller method using ajax in Ruby on

I have exhausted all my Google search attempts, but I still can't find a solution to my problem. My issue is with sending a parameter to a controller method from jQuery using Ajax. Despite my efforts, the method does not seem to get called, as I chec ...

"Exploring the Power of jQuery Validation in the User Experience

Struggling with the decision of when to display error messages in my form validation process. Below is my code, where currently the input fields are being validated on BLUR event, which seems reasonable. However, I am faced with a challenge - I want the v ...

The issue arises when new content is loaded as the bootstrap-popover fails to hide itself

I am facing an issue in my code where I have a div that loads different content types using JQuery. The problem arises when the new content loaded into the div contains popovers that do not disappear when new content is loaded. It seems like they are being ...

The CSS content property within a style element prevents the dragging of elements

Is it possible to make an element with content draggable in HTML while changing the image through replacing the style of the element? I am trying to insert a picture using the content style tag, but it seems to make the element lose its draggable ability. ...

Transfer multiple files by dragging and dropping them into a single file upload option

I was experimenting with adding a drag and drop feature to my website. After trying several scripts, I came across one on CodePen. However, the script allows for the upload of multiple files, while I only need to upload a single PDF or .doc file. Can someo ...

What is the best way to duplicate several HTML input fields using jQuery?

My div is quite intricate with input fields structured like this <input type="text" name="firstname"> <input type="text" name="lastname"> <input type="text" name="email"> <input type="text" name="address"> <div id="section_toC ...

What could be causing my jQuery code to not function properly?

I wrote a small piece of code in jQuery, but I am having trouble executing it. Can someone help me figure out what I'm doing wrong? <html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"> & ...

Utilizing JavaScript to handle the value from a selected form

My form is quite simple: <form id="signup"> <div class="form-group"> <input type="text" name="email" placeholder="Email" id="email" required> </div> <div class="form-group"> <input type= ...

Searching for the element that triggered the event using jQuery or JavaScript

Can anyone offer tips on how to use console.log to identify the element that triggered a hover event? I'm trying to debug an issue specifically on iOS. I'm not looking to locate the specific item that the action was performed on, but rather what ...

I seem to be facing some difficulty in dynamically calling my buttons in AngularJS

Can you assist me in solving this problem? I am new to Angular and just starting out. Initially, there is only one button on load called "Add list". When the user clicks on this button, they are able to add multiple lists. Each list contains a button labe ...

What could be causing my CSS dropdown menu to not display properly?

I'm having trouble getting the dropdown to work when hovering over the li element with "portfolio" in the text. The code seems correct, but nothing happens when I try to hover over "Portfolio." Below is the code snippet: #navmenu ul { position: ...

Getting a variable from an ajax call and using it in a Pug template

Currently, I am experimenting with Express and Pug to learn some new concepts. Upon making a request to a website, I received some dynamic information stored in an array. However, I am facing challenges when trying to iterate over this array using Pug. The ...

Determining the equation from a string and converting it to an integer

I'm working with a table that contains formulas. For example, the formula is: (GP1/(GP1 + GP2))*100%. For my code using jQuery, I need to replace GP1 with the value from textbox1, GP2 with the value from textbox2, and remove the % symbol. My attemp ...

What is a more efficient method for connecting to the pageshow event in jQuery Mobile?

Whenever a page is displayed, whether through regular loading or jQuery Mobile's AJAX navigation, I need to call a specific function. My current code is functional, but I believe there may be a more elegant solution available. In the footer of my pag ...

Tips for modifying the border of an entire column in react-table

My goal is to adjust the style according to the screenshot below. This is what I expect: However, this is what I currently have: As you can see, the border bottom of the last column is not applied as expected. I have tried using the props provided by r ...

Creating personalized dots in the owl carousel

I have successfully added custom previous and next buttons to my carousel using Owl Carousel, but I am having trouble displaying the navigation dots. Can anyone help me identify where I might have made a mistake? // owl.carousel.css .owl-controls { ...

Designing personalized avatars

I am embarking on a new project that involves the creation of multiple custom avatars by users. The idea is to allow users to select images from their inventory and manipulate them within a designated frame. Users should have the ability to move and resize ...

Set the array back to its initial value of 1 using jQuery and

After making substantial edits to this question, I find myself in need of a reset button for the code. The current item needs to be reset back to 1 so that I can use it again, but the issue lies in the fact that only the current item is reset while the hig ...