The issue with the left border color not functioning in JavaScript

Attempting to alter the border-left-color property using this script is resulting in a

Uncaught SyntaxError: Unexpected token -
.

Is border-left-color actually supported?

Javascript

function logoChange() { 
var description = new Array ();
description[0] = "images/logo/blue.png";
description[1] = "images/logo/green.png";
description[2] = "images/logo/orange.png";
description[3] = "images/logo/purple.png";
description[4] = "images/logo/red.png";
description[5] = "images/logo/yellow.png";
var size = description.length;
var x = Math.floor(size*Math.random());
document.getElementById('logo').src=description[x];

var colors = ['#20A3DC', '#72BF48', '#F58623', '#AF3292', '#EA352E', '#FED608'];

var thecolor = colors[x];

$('li span').css({color: thecolor});


$(".orbit-container .orbit-next span").hover(function () {
    $(this).css({
        'border-left-color': thecolor  
    });
}, function () {
    $(this).css({
        'border-left-color': 'black'  
    });
});


$("a").hover(function () {
    $(this).css({
        color: thecolor
    });
}, function () {
    $(this).css({
        color: 'black'
    });
});

}

window.onload=logoChange;

Error message

Answer №1

To ensure proper assignment, remember to enclose both the CSS property and static value in quotes. The correct syntax is:

$(this).css({
    'border-left-color': thecolor  //border-left-color
});

Answer №2

Here are a few options at your disposal:

Opt for using quotation marks:

$(this).css({
    'border-left-color': thecolor
});

Rename the attribute to "snakename":

$(this).css({
    borderLeftColor: thecolor
});

If you have only one property to modify, consider simplifying it like so:

$(this).css('border-left-color', thecolor);

Answer №3

When incorporating CSS properties through jQuery, it is important to adhere to camel casing. For example, border-bottom should be written as borderBottom, and border-left-color should be coded as borderLeftColor

Answer №4

Make sure to wrap it in a string literal:

... $(this).css({
     'border-left-color':  theColor
    });
..

Answer №5

Give this a shot:

$("selector").css('border-left', 'solid 1px red');

Check out the live demonstration here: http://jsfiddle.net/9Q9Vm/1/

Answer №6

There are two choices available to you.

In Quotes:

$(this).css({
    'border-left-color': '#AAA'
});

Using CamelCase:

$(this).css({
    borderLeftColor: '#AAA'
});

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

Navigating the grid layout in Material UI can be tricky to

I'm struggling to grasp the concept of the grid system in material UI. Within my grid container, I have two grid items that I want to be centered and occupy the entire width. The button element appears centered, but the typography element does not. A ...

Discovering which page the form was submitted from using xsl template

Incorporating code like <input type="hidden" value="contact-form-1" name="getpage"> into my form is something I'm interested in, as it allows me to retrieve the URL of the page from which the form was submitted. The challenge arises because the ...

The process of reversing an array is not fully completing due to the pop method being used within a loop

Note: I've been immersed in code for hours now and have reached a stage where I'm starting to doubt the spelling of every word or question if I have dyslexia. Despite this, I know this should be a simple question. I want to create a basic functi ...

Preventing select from opening when closing chip in Vuetify: A simple guide

Looking at this specific situation on vuetify.com https://codepen.io/anon/pen/RqoxXY?&editors=101 Regarding the autocomplete feature with chips, is there a way to prevent the select menu from opening when I cancel a chip? I attempted using @click.st ...

Utilizing AngularJS: Triggering a controller function from a directive

I am currently working on a project with a model named 'user', which includes a controller called 'login' and a directive called 'userMenu'. My goal is to have the userMenu directive utilize the 'login' controller th ...

Difficulty displaying a progress bar over an overlay

Issue with Progress Bar Visibility in AJAX Call: I have a requirement to display a progress bar in an overlay after the save button is clicked. However, the progress bar is only visible after we receive the response from the AJAX call and display an aler ...

How can I manually set a date in Angular bootstrap datepicker?

Using the Angularjs Bootstrap datepicker has been a great experience, but I encountered a problem when attempting to select the date using JavaScript. How can I ensure that the selected date in the datepicker matches the date read from a specific object, s ...

Python's Selenium Throws No Such Element Exception

Looking to automate tasks involving hyperlinks on my university's SAP Portal, I decided to use Selenium. However, encountering difficulties as many web elements are dynamically generated using JavaScript, making them invisible to the webdriver. The e ...

Tips for iterating through data in JSON format and displaying it in a Codeigniter 4 view using foreach

As a newcomer to JSON, I have a question - how can I iterate through JSON data (which includes object data and object array data) using jQuery/javascript that is retrieved from an AJAX response? To illustrate, here is an example of the JSON data: { "p ...

What is the best way to connect a CSS file with multiple pages located within a specific folder in HTML/CSS?

In my CS 205 class project, I am tasked with creating a website. To accomplish this, I used Notepad++ for the HTML files and Notepad for the CSS files. The site consists of an index.html page along with other content pages, each designed separately in Note ...

Having trouble sending data from jQuery to Flask when the user clicks the Sign In button

I have been working on a Flask application that includes a user sign-up button. However, I am facing an issue where no values are returned after clicking the button. In my code, I have added a jQuery POST request for when the user clicks the Sign Up butto ...

Expand a section of the webpage to fill the entire screen

I'm working with some HTML code that looks like this: <header>title</header> <content class="container-fluid"> <div class="row"> <div class="col-sm-3 leftside"> <ul> <li>test</li> ...

My webpage lacks responsiveness

I've recently put together an HTML page, but unfortunately, it's not responsive. My Code <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> ...

Aligning content within an <a> container

I am in the process of creating a square box that is clickable and will redirect users to another page. To achieve this functionality, as well as implement hover effects later on, I am utilizing the < a > element. Below is the HTML markup: <a id ...

Encountering an issue when trying to generate a button in Angular

I am currently using JavaScript to dynamically create a button in Angular. While I have been successful in creating the button, I am encountering an error when attempting to change the classname. The error message I am receiving is: Property 'clas ...

Ensuring the width of a div matches the adjacent containers

I need assistance in creating a form that adjusts its width based on the form fields. The form contains both explanatory text and input fields, each enclosed in a div with inline-block set. The outer div (also using inline-block) should not expand beyond ...

How to activate a window that's been minimized in Chrome

I am experiencing an issue with a button that is supposed to open a new window as a popup below the parent page. It works correctly in IE and Firefox, but in Chrome, the popup appears on top of the parent window. Can someone please provide a solution? Fo ...

Warning: Promise rejection not handled in error

I've been working with nodejs, express, and argon2 in my project. However, I encountered an error that has left me puzzled as to why it's happening. Strangely, even though I don't have any callbacks in my code, this error keeps popping up. H ...

Absolute positioning causes an element's height to increase

As I delve into the realm of typographical animations and seek to calculate the baseline of a font at various sizes, I've stumbled upon a peculiar discovery: It appears that the height values of elements tend to increase in an erratic manner when thei ...

PHP not cooperating with AJAX POST method, only GET is functioning as intended

I'm having trouble sending a POST request to php using Ajax. When I use GET everything works fine, but with POST the data received in php is empty. I am sending the data as json. Below is the JavaScript code: $.ajax( { type: &ap ...