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 3980286
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:16:21+00:00 2026-05-20T05:16:21+00:00

I have the following: <a href=javascript:jQuery(‘body’).css(‘backgroundColor’,’red’);>Test</a> When run in Chrome, it functions as expected

  • 0

I have the following:

<a href="javascript:jQuery('body').css('backgroundColor','red');">Test</a>

When run in Chrome, it functions as expected and turns the page red. However, in Opera I get:

[object Object]

Closer inspection reveals that Opera thinks that javascript:Query('body')... is some kind of URL. What am I doing wrong? Doesn’t Opera recognize javascript: links in the href attribute?

jsFiddle: http://jsfiddle.net/9CZZL/


Edit: seems to be a Firefox problem too…

  • 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-20T05:16:21+00:00Added an answer on May 20, 2026 at 5:16 am

    The issue is that the return value of jQuery('body').css('backgroundColor','red') is an object, which some browsers interpret as the new content for the web page. To fix this, you can use the JavaScript void operator to turn it into undefined, which FF and Opera (and potentially others) will handle as you intended. You will notice that this issue is also described on that page, since it’s the premier use-case of the void operator (other than code golf where void 0 is less characters than undefined).

    <a href="javascript:void(jQuery('body').css('backgroundColor','red'));">Test</a>
    

    This should give the intended result: http://jsfiddle.net/9CZZL/13/

    It should be noted that handling clicks this way is considered bad practice. Instead, using event handlers in JavaScript is recommended. This helps separate the different layers of your web app, which in turn will make debugging in the future easier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code, written using jQuery: var strval = '22' $(#quicknote).attr(href, javascript:location.href=/'http://site.com/notes/add?projects=/'+
So I have the following Jquery calling a Javascript method $j(a.Pinterest).attr(href, javascript:void(addScript());); And this
I have the following code: echo <script type='text/javascript'> if(window.location.href.toLowerCase().indexOf('test') != -1) { } else
I have the following javascript. window.location.href = _searchUrl + query.replace(/\s+/g, '+') .replace('/', '-') .replace('\\','-')
I have the following code on the my page... <a href=javascript:change_product_photo(2);><img id=alternate_product_photo_2 style=border-color:#666666; src=/v/vspfiles/photos/00-6189-2S.jpg
I have the following code: <html> <head> <script type=text/javascript language=javascript src=jquery/jquery-1.5.1.js></script> <script type=text/javascript language=javascript
I have the following HTML in a page: <a href=javascript:void(0) class=move-next><img src=/Content/images/small-next-arrow.png height=16 width=16
I have the following link which opens a jquery modal window: <div id='confirm-dialog'><a href='#'
Hi guys lets say I have the following html: <div class=owner> <div> <a href=javascript:void(0)
I have following databases: test table1 fields: id, password, name, lastname test2 table2 fields:

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.