473,770 Members | 4,544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Toggle colour change on click

KeredDrahcir
426 Contributor
I have a division and I want to click on it to change the colour to red and click on it again to change the colour back to black.
The code I'm using doesn't seem to work and I can't work out what I'm doing wrong. Can anyone help me?

HTML
Expand|Select|Wrap|Line Numbers
  1. <div style="width: 30px; height: 30px; border-style: solid; border-color: #ffffff; border-width: 2px 0 0 2px; float: left; background-color: #000000;" id="a1" onclick="plan('a1');">&nbsp;</div>
JavaScript
Expand|Select|Wrap|Line Numbers
  1. function plan(id){
  2.     var obj = document.getElementById(id);
  3.     (obj.style.backgroundColor == "#000000") ? obj.style.backgroundColor = "#ff0000" : obj.style.backgroundColor = "#000000";
  4. }
Many thanks.
Aug 3 '13 #1
2 1660
yolshevsky
2 New Member
This works.
Expand|Select|Wrap|Line Numbers
  1. obj.style.backgroundColor = (obj.style.backgroundColor == "rgb(0, 0, 0)") ? "#ff0000" : "#000000";
  2.  
apparently the background property is not a string.
Aug 4 '13 #2
KeredDrahcir
426 Contributor
Fantastic. Works perfectly. Many thanks.
Aug 4 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
5236
by: Louise | last post by:
Hi I have written an HTML pages which does not have any colour specifying tags as far I know. When I view this in an Microsoft internet explorer browser it appears with a white background and black text but when I change Windows start menu->settings->control panel ->display -> appearance and change scheme to 'High Contrast Black' the background in the browser changes to black and the text to white. I understand that the windows scheme...
1
1471
by: JD | last post by:
How do i get rid of the 1st column that appears in a datagrid? I do not want this? Also how do i change the colour of the background of a cell when the user selects it. i.e for the first coloumn i have made this non-editable and therefore i do not want the graey colour that appears when the user clicks on a cell in the first row. As only my second row is editable, i only want a click colour for this coloumn
2
6630
by: Scott | last post by:
Is it possible to have a button change colour OnClick ? Thanks.
4
8600
by: Bob | last post by:
Hi, Is it possible to change the forecolor of a disabled text control. I have a RichText Box that I don't want the user to edit but the Grey on Grey default is hard to read. Is there a way of overriding this with a custom colour? I had a quick foray into the forms Paint event handler but no joy. Thanks Bob
2
4242
by: sathiyamurthy | last post by:
Hi all I need help regarding button colour change in vc++. tell me the steps to implement. also i want to change the button label text size. is there any function for that. Regards sam
23
8764
by: cmcdermo | last post by:
I want to change the colour of a border around an image when a user clicks on the image. Not sure how to go about this, i have tried a few things but it doens't seem to work. here is my image. <img src="images/canvas_colours/images/canvas_taupe_small.gif" alt="Taupe" name="taupe_small" id="taupe_small" style="cursor:hand;border-Style:solid;border-Width:2px;border-Color:white"> This is what I tried.
0
1008
by: swansea29 | last post by:
Hi, I have created a subform in my database where actions are input, the request has come from my peers that when they complete there relevent action " they click a checkbox" can it change the colour of that particular record automatically. this would enable people to quickly brouse through the action list as i have 2 diffrent colour actions Regards James
2
6104
by: gvrajkumar | last post by:
Hi We are developing an Ajax based application. In this application the URL is fixed and as user navigates on the application we will change Anchor on the URL so that user can bookmark the url and can load the page on demand. When user refreshes the page we have no issue in the populating the page based on the anchor in URL as on load we can capture the hash(#anchor) and act accordingly.
1
2134
by: warder21 | last post by:
Hi All, Not sure wether this is a css issue or javascript but here goes. I am trying to make some html <p> tag text highlight (change colour) when hovering over an image that is relevant to that text. Does anyone know how this could be done or wther there is some script to download and modify to do this? Many thanks in advance for any help Warder
2
1393
by: Sean Cutting | last post by:
Hi, Please can you help? I would like to build a website where the colour of the site will change to one of the 4 brand colours everytime the site is refreshed. Can this be done? Regards, Sean.
0
9591
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10002
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9869
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3575
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.