New to jQuery: struggling with click event and CSS... What am I missing here?

I have a very simple question for you:

$j(".srch-txt").click(function() {
$j(this).css("color:" "#155D97")
});

$j is used to avoid conflicts

It's quite straightforward: I want to change the color of the .srch-txt element to #155D97 when it is clicked.

Can you help me figure out where I made a mistake?

Answer №1

Don't forget to include a comma and remove the extra colon in your code:

$j(this).css("background-color", "#1A7F54");

Answer №2

Try replacing color: with just color and check if it resolves the issue.

Answer №3

There is no need for the colon after the css attribute.

Answer №4

$j(".search-text").on("click", function() {
$j(this).css("color", "#569812")
});

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

Is there a way to identify the specific list item that a draggable element has been dropped onto within a jQuery sortable with connected draggable lists?

Take a look at these two sets of items: user's inventory <ul id='list1'> <li>Apple</li> <li>Banana</li> </ul>available products <ul id='list2'> <li>Orange</li> ...

Populate a dropdown menu using JSON data

I am working with an SQLite table that has columns for id and name. I have created a JSON array of rows from the autocomplete.php page. Now, I am trying to populate a dropdown list in my select element using this JSON data by utilizing jQuery and JavaScrip ...

Animating Angular ng-template on open/close state status

I am looking to add animation when the status of my ng-template changes, but I am unable to find any information about this component... This is the code in my report.component.html <ngb-accordion (click)="arrowRotation(i)" (panelChange)="isOpen($even ...

Cancel the use of the $.each method when the specified variable is located

Currently, I am utilizing a $.each method to search through a JSON in order to find a specific variable. Here is the code snippet I am working with: $.each(heroes_json.heroes, function(key, val){ if(val.id == hero){ hero = val.localized_name; ...

Ensure that a DIV element stretches beyond the limits of its container

I am having an issue with a div that should overlap everything else as it functions as a menu. Despite trying various positioning tricks, the desired effect is not achieved. The div is only shown when hovering over a certain element. Here is the structure ...

Save the Selenium HTML source code into an HTMLDocument element

Is there a way to save the HTML code fetched using Selenium (via Excel VBA) into an HTMLDocument element? The following example demonstrates utilizing Microsoft Internet Controls and Microsoft HTML Object Library for automating Internet Explorer. Dim IE ...

What is the JavaScript mouseenter/out event all about?

My goal is to create a hover effect using JavaScript. I am utilizing the mouseenter and mouseout events to display the content when the mouse hovers over a button and remove the content when the mouse moves out. However, I am facing an issue where the cont ...

Why is the "text-overflow: ellipsis" property of a parent div not functioning properly for its child div?

Why is the CSS property text-overflow: ellipsis not working on a child div with the class name cluster-name? .ft-column { flex-basis: 0; flex-grow: 1; padding: 4px; text-overflow: ellipsis; overflow: hidden; } .ft-column > .cluster-name { ...

The PHP response is constantly changing and adapting, creating

My webpage has a button that triggers an ajax request to a php page, all working well. I have a database called messages, with columns for "id", "receiver", "sender", and "message". Let's say there are two entries in the database where both the sender ...

What is the best way to achieve a smooth rotation effect ranging from 1° to 359° using HTML/CSS in conjunction with JavaScript

Currently, I am retrieving rotation data from a sensor and transmitting it to a webpage containing a 2D-Model that rotates based on this data. To ensure a smoother motion, I have incorporated a CSS transition. However, an issue arises when the rotation da ...

Changing the background color of navigation items when the navbar in Bootstrap 4 adjusts for responsiveness

Hi there, I'm having an issue with my Bootstrap 4 navbar. When I test the responsiveness of my page, the background color of my nav-items disappears and only the text is visible. Can someone guide me on how to maintain the navbar color when I click th ...

Changing the text of a link when hovering - with a transition

Seeking a straightforward way to change text on a link upon :Hover. I desire a gentle transition (text emerges from below) and fallback to default if JavaScript is disabled. HTML <div class="bot-text"> <a href="">Visit this site</a> ...

Bring in a JavaScript file from Blogger without using a tag

Is there a way to retrieve blogger feeds code without using <script src=? I attempted to achieve this using document.write, but it resulted in the deletion of the original page content upon import. Is there an alternate method to import when triggering ...

Troubleshooting problem with clicking on SVG within an HTML <div>

I currently have a parent container with a child object tag that houses my svg. I've been attempting to detect clicks on my image, but unfortunately, it's not functioning as expected. In the provided code snippet, the alert message only appears ...

I am attempting to eliminate an inline style that includes an important declaration, and despite my efforts to override it with a custom.css file, I am unable to do

I have been researching jquery statements to disable inline styles, but after spending several hours searching for a solution, I am still unable to figure it out. I can identify the inline styles I wish to override and can temporarily change them in Fireb ...

Exploring the World of FLV Video Playback in JSP and Java EE

I'm looking to incorporate FLV videos into my website, but I'm encountering an issue with my FLV player, JW Player. The video files I want to use are not stored on my server, so I only have the URL for them. Unfortunately, the URLs do not end in ...

Is it possible to blend an established static HTML website with a fresh CMS site on the same domain name?

Our small society, cmyf.org.uk, has had a static html website for many years. We are now looking to incorporate blogging and other features into our site. Our main concern is whether we should create a new CMS site with a different domain name or if ther ...

What is the reason for the 'scrollHeight' being considered 'undefined' in this particular scenario, and why did the iframe encounter an error when switching to the html-file?

This is my first time asking a question, so please forgive any mistakes... I am attempting to create a website using HTML, CSS, and JavaScript on my Raspberry Pi with Apache2. I have written a script for an automatic iframe height function based on the co ...

What is causing this code to keep iterating endlessly?

I have a basic jquery script embedded in my HTML code that utilizes the cycle plugin for jQuery. The problem I'm facing is that when I interact with the slideshow using the "next" or "previous" buttons, it continues to loop automatically after that in ...

Populate JQuery fields dynamically based on changing name elements

I am working on a section that displays products dynamically fetched from a database using an ajax call. The results vary, some are single-row while others have multiple rows. Initially, I have a placeholder row of HTML on the main page for data entry whic ...