Ways to alter the color of a link after clicking it?

Is there a way to change the link color when clicking on it? I have tried multiple approaches with no success. The links on this page are ajax-based and the request action is ongoing.

        <div class="topheading-right">
        <span>
            <?php echo $this->Manager->link('Archived Events', array('a'));?>
        </span>
        <?php echo $this->Manager->link('View All', array(''));?>
    </div>
</div>

<div id='events-event_list' class='dashboard-<?php echo __l($product_name);?>s'>
    <?php echo $this->requestAction(array('controller'=>'events', 'action'=>'view_event_list', $is_archive), array('return'));?>
</div>

Any suggestions on how to achieve this? Appreciate the help in advance.

Answer №1

When dealing with an AJAX link, the :visited pseudoselector cannot be utilized.

For this scenario, consider using:

 $('a').on('click',function(){this.style.css.color='red'})

or a similar approach

Answer №2

Experiment

$('.clickable-links').on('click',function(event){
   event.preventDefault();
   var Element = $(this);
   Element.css('color','blue');
   var link = Element.attr('href');
   //make ajax request using link
});

Answer №3

This is an example of how it can be done:

 $('button').on('click',function(){
     $(this).addClass('active');
 });

Answer №4

When using modern browsers (including IE10), simply setting the a:active pseudo-class will result in the desired outcome without the need for JavaScript:

a:active{ color: red; }

Additional attributes can also be assigned as needed.

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

Improving React code by using conditional statements such as IF and Else

Currently, I am delving into the world of React and have managed to devise some logic for rendering a DIV. However, upon reflection, it has become evident that there is redundancy present in my code structure and I am uncertain about how to efficiently ref ...

Pressing the Add button will create a brand new Textarea

Is it possible for the "Add" button to create a new textarea in the form? I've been searching all day but haven't found any logic to make the "Add" function that generates a new textarea. h1,h2,h3,h4,h5,p,table {font-family: Calibri;} .content ...

Utilizing JQuery for showcasing a success message in ASP.NET WebForms

I have recently integrated jQuery into my new ASP.NET webform application. I am aiming to show a success message upon insertion when a button is clicked. Below is the link button code: <asp:LinkButton ID="LbOk" runat="server" CssClass="regular" oncl ...

What makes the creation of Javascript objects so flexible and dynamic?

Recently, I've been exploring the concept of creating new objects in JavaScript. It's interesting to note that in JS, every object creation is dynamic. This allows you to create an object and then add properties later on. Even fields created in t ...

Implement jQuery pagination with AJAX in PHP

I’m encountering an issue with pagination where the functionality of adding products to the cart only works on the first page. When I navigate to the second page and attempt to add products, the Ajax feature fails. Is there a way to make it work on the ...

Is pl/pgsql block code supported by postgres-nodejs?

I am attempting to define a custom UUID variable that can be utilized across multiple queries within a transaction. Initially, I attempted using a JavaScript variable which ultimately defeated the purpose of declaring the variable on the server side. The ...

Creating a fetcher that seamlessly functions on both the server and client within Nextjs 13 - the ultimate guide!

My Nextjs 13 frontend (app router) interacts with a Laravel-powered backend through an api. To handle authentication in the api, I am utilizing Laravel Sanctum as suggested by Laravel for SPAs. This involves setting two cookies (a session and a CSRF token) ...

What is the best way to validate if fields are blank before sending a message using the button?

<template> <div> <div class="form-group"> <label for="name">First Name</label> <input type="text" class="form-control" v-model="firstName" placeholder="Ente ...

Customizing text appearance with innerHTML in JavaScript: A guide to styling

Below is the code I have for a header: <div id="title-text"> The Cuttlefisher Paradise </div> <div id="choices"> <ul> <li id="home"><a href="#">Home</a></li> <li id="contact">&l ...

Text within cells is not wrapping onto a new line in an HTML table

Let me show you how it currently looks: https://i.sstatic.net/OeHRg.png The maximum width of the cell is working properly, but the text is not wrapping to a new line as expected. Instead, it overflows out of the cell. Here is the CSS applied to the tabl ...

"Exploring the world of remote_form_tag in Rails with jrails

After transitioning to jQuery with jRails for my application, most of my previous RJS code is working perfectly. However, I am facing an issue with the :loading => callback when using the remote_form_tag. <% form_remote_tag :url => '/hostels ...

Missing Cookie in request using NodeJS and NextJS

Struggling with integrating cookies in a fullstack app I'm developing using Node for backend and NextJS for frontend on separate servers. The challenge lies in getting the browser to attach the cookie received in the response header from the node serv ...

Retrieve the component information from the JavaScript function located outside of the main code

Is there a way to retrieve the component data using an external JavaScript function? I am looking to access markers, labels, and images. Vue.component('home', { template: '#home', data: () => ({ markers: [ ...

Guiding users who have disabled JavaScript through redirection

When faced with the following markup, users whose browser has JavaScript disabled will be redirected to an alternative page. This alternate page may attempt to mimic the site's functionality without JavaScript or simply display a warning message infor ...

One way to eliminate a prefix from a downloaded file path is by trimming the URL. For example, if you have a URL like "http://localhost

As my web app runs on port number, I am looking to download some files in a specific section. However, the download file path is being prefixed with "". <a href={file_path} download={file_name}> <Button variant={"link"}> <b>Dow ...

Updating React component when a property in an array of objects changes by utilizing the useEffect() hook

In my current project, I am creating a React application that resembles Craigslist. In this app, logged-in users can browse through items for sale or services offered. When a user clicks on an item, they are able to view more details and even leave a comm ...

Utilize async/await to send images using node mailer

How can I correctly access mailOptions in the triggerExample.ts file? mail.ts: export const sendNewMail = async (html: string, emails: string[]) => { let smtpTransport = nodemailer.createTransport({ service: "Gmail", auth: { u ...

Issues with iterating over JSON objects are causing errors

I have been attempting to loop through a JSON object using the code below, but I am encountering issues with the iteration: function iterateRows() { var timein_rows = [{"id":"72","date":"2012-08-01"},{"id":"73","date":"2012-08-01"}]; $.each(timein ...

Why isn't the card positioned in the center of the screen?

Why is the card not centered on the screen as it is supposed to be? I am utilizing Bootstrap 4.5 <div class="container"> <div class="row"> <div class"col"></div> <div class="col-8"> <div class="card"> ...

Executing Ajax requests with callbacks in JavaScript/jQuery

I'm facing an issue where my functions are executing before Ajax requests (first fetching local JSON, then retrieving data from an online resource) have completed. For example, I want countTheMovies to run only after all the necessary information is ...