Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7087351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:39:50+00:00 2026-05-28T07:39:50+00:00

I am wanting to update a css attribute using jQuery but it isnt working.

  • 0

I am wanting to update a css attribute using jQuery but it isnt working. Using the alerts in the code below my first alert brings up

url("file:///H:/Web/example/HTML/images/red-arrow-up.png")

but then the second alert (in the if statement) brings up

[object Object]

But what i want it to do is update the attribute and change up to down in the url. Any idea what im doing wrong?

    $(document).ready(function() {
        $( ".portlet-header" ).click(function() {
            var currValue = $(this).children(".portlet-arrow").css("background-image");
            alert (currValue)
            if ($("currValue:contains('up')"))  {
                var newValue = $(currValue.replace("up", "down"));
                alert(newValue)
                $(this).children(".portlet-arrow").css("background-image", newValue)    
            };
            if ($("currValue:contains('down')"))    {
                var newValue = $(currValue.replace("down", "up"));
                alert(newValue)
                $(this).children(".portlet-arrow").css("background-image", newValue)    
            };
        });
    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:39:50+00:00Added an answer on May 28, 2026 at 7:39 am

    This basically all comes down to going over-the-top on jQuery selector syntax without having read the documentation to find out what selectors actually do.

    1. Why did you surround currValue.replace("down", "up") in $()? That looks like an attempt to create a jQuery object out of a string that contains the URL to an image. Don’t do that. Arbitrary Javascript code isn’t to be surrounded in $() for no reason.

    2. Also, $("currValue:contains('down')") doesn’t do what you think. That syntax is for selecting DOM nodes based on certain criteria, not for implementing arbitrary conditional statements on strings. You just want to search within a string.

    $(document).ready(function() {
        $(".portlet-header").click(function() {
            var currValue = $(this).children(".portlet-arrow").css("background-image");
            alert(currValue);
            if (currValue.indexOf('up') != -1) {
                var newValue = currValue.replace("up", "down");
                alert(newValue);
                $(this).children(".portlet-arrow").css("background-image", newValue);
            }
            if (currValue.indexOf('down') != -1) {
                var newValue = currValue.replace("down", "up");
                alert(newValue);
                $(this).children(".portlet-arrow").css("background-image", newValue);
            }
        });
    });
    

    The code can be improved further:

    $(function() {
        $(".portlet-header").click(function() {
    
            var currValue = $(this).children(".portlet-arrow").css("background-image");
            alert(currValue);
    
            if (currValue.indexOf('up') != -1) {
                var newValue = currValue.replace("up", "down");
            }
            else if (currValue.indexOf('down') != -1) {
                var newValue = currValue.replace("down", "up");
            }
            else {
                return;
            }
    
            alert(newValue);
            $(this).children(".portlet-arrow").css("background-image", newValue);
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the code below <div id=topbar> <a class=nav href=# onClick=if($('#embedding').css('display') == 'none') {
I am pushing out a larger model to a view, but wanting to update
I am pushing out a larger model to a view, but wanting to update
I am wanting to update a view dynamically by applying applyBindingsToNode to it but
I'm wanting to update a record in my database which has two values, one
Wanting to implement authentication by client certificates I am experiencing some issues. First some
I've started the following skeleton for an ajax/post/update function I'm wanting to write in
I was wanting to create a small tool in Delphi which can update the
I am wanting to update all the rows in the RESULTSET from the SELECT
Within my android application, I'm wanting to update an ImageView, with an image specified

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.