Explore the functions of jQuery's .css() method and the implementation of

Could use some assistance with the .css() method in jQuery.

Currently working on a mouseover css menu, and encountering an issue when trying to include this code:

$(this).siblings().css({backgroundColor:"#eee"});

at the end of my script. It seems to interfere with my mouseover function.

$(".principal").click(function()
{
    $(this).css({backgroundColor:"#861b1b"}).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
    $(this).siblings().css({backgroundColor:"#eee"});
});

The problem I'm facing is that while my menu functions with css :hover, I need to revert the P color to gray. Is there a solution to address this issue?

<div>
    <span>Ventanas</span>
    <p class="principal">Fijas</p>
    <div class="menu_body">
    <a href="products.php?ref=fijo&tipo=7001ad">Normal (7001)</a>
    <a href="products.php?ref=fijo&tipo=7001ad">Normal (7001)</a>
    <a href="products.php?ref=fijo&tipo=7001ad">Normal (7001)</a>
    <a href="products.php?ref=fijo&tipo=7001ad">Normal (7001)</a>
    </div>
</div>



    div.sdmenu div p {
    cursor:pointer;
    padding: 5px 10px;
    background: #eee;
    display: block;
    border-bottom: 1px solid #ddd;
    color:#000;
    text-decoration:none;
    margin: 0;
}

div.sdmenu div p:hover {
    background:#841c1c;
    color: #fff;
    text-decoration: none;
}

Answer №1

There seems to be an issue with the syntax being utilized in this code snippet:

$(this).siblings().css({backgroundColor:"#eee"});

To rectify this, try using the CSS element without curly braces like so:

$(this).siblings().css(backgroundColor,#eee);

Remember, the correct syntax is: .css( propertyName, value )

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

Using jQuery and AJAX to submit a dynamic form

I am currently facing an issue with cloning a HTML drop down list using jQuery. The main problem I am encountering is that there seems to be no restriction on the number of cloned sections, and I need to store all these sections in a mySQL database. How c ...

Is there a way to click on a button and have its background color change randomly each time?

I am facing an issue with a button on my HTML page. When the button is clicked, I want its background color to change to a random different color. However, despite trying various sources, I am unable to get it right. It seems like I am not placing the code ...

A layout featuring nested buttons and links within a card element, utilizing the power of Link in NextJs

After extensive searching on S.O., I have been unable to find a solution that works flawlessly. The issue at hand involves a card component in a NextJs application that is encompassed within a <Link> tag. Additionally, there is another <Link> t ...

Combining ajax and jsp to fetch data for a servlet

In my JSP file, I have two text fields - signUp and post. I want the post text to be sent to a servlet using AJAX function while the signUp text should be sent in the usual way through request.getParameter(). Can these two functionalities be combined with ...

Tips on widening a paper to its fullest width while also keeping it versatile and adaptable

How can we ensure that in a React application using Material-UI, the width of a paper always expands to a maximum of 600px, regardless of the width of its contents? We also want to keep the paper flexible, so that when the parent container's width shr ...

Tips for updating the left positioning of a Div element on the fly

Although my title may not fully explain my goal, I am dealing with dynamically created div elements. When a user triggers an ajax request to delete one of the divs, I want to remove it from the DOM upon success. The issue arises in adjusting the layout aft ...

Convert JSON data into jQuery format, then present it in a list format using `<ul>` and

After making an ajax request, I receive a JSON string containing error messages regarding required form fields: first name, last name, email, usercode, password, password confirmation, and captcha. { "first_name":["The first name field is required."], " ...

Is it possible to modify @page directive(CSS) values from the code-behind(C#) or JavaScript?

Using the @page directive, you can define the printer margins for a page separately from regular CSS margins: <style type="text/css" media="print"> @page { size: auto; /* auto is the current printer page size */ margin ...

What is the process for obtaining X through the use of createElement('img')?

Is there a way to retrieve the X position from the left of the tag created using document.createElement('img'); var block00 = document.createElement("img"); block00.src = "images/sep1.png"; If so, how can it be done: if (block00.getBoundingCli ...

Containerized chatboxes with improved stability

Within the div labeled chatbox-container, there are two chatboxes that have been positioned to float: right with a margin-right: 15px. .chatbox-container { position: fixed; z-index: 1; right: 0; left: 0; bottom: 0; } An issue arises ...

How can I add divs to an HTML page with a Javascript animated background?

I am currently facing an issue with my JavaScript animated background, consisting of just 3 pictures. I am trying to display some Div elements on it with content inside. Here is the code snippet I have right now: In my CSS file, I have defined styles for ...

Prevent fixed div from overlapping with footer

I have been trying to find a solution for my fixed div that sticks to the bottom, but nothing seems to work. My goal is to have the div stop when it reaches the #footer section of the page. Visit the site The CSS currently in place gives the div the cla ...

Transferring variables from the $(document).ready(function(){}) to the $(window).load(function(){} allows for seamless and

Just think about if I successfully create percent_pass at the time of document.ready, how can I transfer that variable to window.load? $(document).ready(function() { jQuery(function() { var ques_count = $('.question-body').length; va ...

Is it possible to display a variety of color schemes in just one console.log()?

My task involves working with an array of hexadecimal values, "colors": ["#d5dd90","#e6bb45","#ef9770"] To log these out in different colors, I used the following method: colors.forEach((value)=>{ console.log(& ...

The process of making an image fill an entire div using Html and CSS

What is the best way to make an image fill an entire div using Html and CSS? ...

Exploring the Combination of Laravel 5.1 with Typeahead.js

I am facing an issue with implementing typeahed.js in my Laravel 5.1 blade view. I'm following The Basics example for typeahed but the states are not showing up when I try to search for them. Here is the code for my main layout: <html> <h ...

Animating a CSS overlay

My goal is to design an overlay using the following HTML and CSS code snippets div.relative { position: relative; width: 400px; height: 200px; border: 3px solid #73AD21; } div.absolute { position: absolute; top: 50%; right: 0; width: 20 ...

Observing the data retrieved from an AJAX request

Currently, I have this AJAX call in my code: $('#search').keyup(function() { $.ajax({ type: "GET", url: "/main/search/", data: { 'search_text': $('#search').val() }, suc ...

Learn how to utilize AngularJS Material to toggle the enable/disable functionality of a checkbox

Can someone assist me in enabling and disabling the checkbox as shown in the attachment image https://i.stack.imgur.com/l6g1C.jpg View the PLNKR angular.module('BlankApp', ['ngMaterial']) .config(['$mdThemingProvider', fun ...

Using AJAX to get the response from a static [webmethod] - a guide

On my Default.aspx page, I have the following PageMethod: [WebMethod] public static string Hello() { return "Hello"; } I want to set the text of a div to whatever is returned via AJAX: <div id="ajaxDiv"></div> Below are two methods I us ...