473,657 Members | 2,524 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't figure out where my mistake is. I want the two texts to turn blue and yellow.

5 New Member
Expand|Select|Wrap|Line Numbers
  1. <style>
  2.  
  3. .blueback {
  4.   background-color="lightblue";
  5.  
  6. }
  7. .yellowback {
  8.   background-color="yellow";
  9.  
  10. }
  11.  
  12. </style>
  13.  
  14. <h1>
  15.   Change CSS Classes
  16.  
  17. </h1>
  18. <div id="d1">Hello</div>
  19. </br>
  20. <div id="d2">GoodBye</div>
  21. </br>
  22. <p>
  23. <input type="button" value="Change Color!" onclick="colorchange()">
  24. </p>
  25.  
  26.  
  27. <script>
  28.  
  29. function colorchange() {
  30.  
  31.   var dd1=document.getElementById(d1);
  32.   var dd2=document.getElementById(d2);
  33.  
  34.   dd1.className ="blueback";
  35.   dd2.className ="yellowback";
  36.  
  37.  
  38.  
  39. </script>
Reply·Email·Vie w Thread | Edit·Delete
Sep 30 '19 #1
2 2320
gits
5,390 Recognized Expert Moderator Expert
there are several issues in that code:

1. css properties are assigned like the following:

Expand|Select|Wrap|Line Numbers
  1. propertyName: value
2. getElementById takes a string as argument

3. function body needs to be closed

use the browser's developer tools to check the errors and fix them.
Oct 1 '19 #2
AjayGohil
83 New Member
Hi,

In Your code there are several code is missing:

In CSS property:value; //remove = and " "

Example:
Expand|Select|Wrap|Line Numbers
  1. background-color:lightblue; 
In Javascript,

In script tag add type="text/javascript" and complete } Brackets

You can also try this code:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <title>Document</title>
  5. </head>
  6. <style>
  7.     .blueback {
  8.       background-color:lightblue;
  9.  
  10.     }
  11.     .yellowback {
  12.       background-color:yellow;
  13.     }
  14.     </style>
  15. <body>
  16.     <h1>
  17.         Change CSS Classes
  18.  
  19.       </h1>
  20.       <div id="d1">Hello</div>
  21.       </br>
  22.       <div id="d2">GoodBye</div>
  23.       </br>
  24.       <p>
  25.       <input type="button" value="Change Color!" onClick="colorchange()"/>
  26.       </p>
  27.  
  28.  
  29.       <script type="text/javascript">
  30.  
  31.       function colorchange() {
  32.           //You can use this syntax for calling css class
  33.         document.getElementById("d1").className ="blueback";
  34.         var dd2=document.getElementById("d2").className ="yellowback";
  35.  
  36.       }
  37.       </script>
  38.  
  39. </body>
  40. </html>
Jan 28 '20 #3

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

Similar topics

4
1443
by: nichas | last post by:
the code is ... int main(void){ static int a={1,2,3,4,5}; static int *p={a,a+1,a+2,a+3,a+4}; int i; for(i=0;i<5;i++){ printf("%u\n",a+i);} printf("\n%u\t%u\t%d",p,*p,*(*p)); return 0; } Now in this code the output which iam getting is :::
6
2188
by: Peter Row | last post by:
Hi, Can someone give me a set of steps for an ASP.NET project (well actually its just a VB.NET class DLL that implements HttpHandler) that will work when moved to another developers machine? Here are some specifics: 1) The code, project/solution files are in MS Visual Source Safe
2
1187
by: Rehor | last post by:
I'm just starting with ASP.NET and C#. On one of my web forms I created has a dropdown list of choices. Once a choice is made, the postbacked page displays a list of links to documents in an unordered list using Response.Write in the codebehind page. It works very well except ... the unordered list appears at the top of the postbacked page with the header user control and the dropdown box at the bottom of the page after the unordered...
9
2219
by: AFN | last post by:
I was just dropped into someone else's code (isn't that always so fun?). I can't figure out why a custom validation control's server event function is executing. There is nothing (that I see) in page_load, or elsewhere, that says page.validate, no control says "causesvalidation=true", and the AutoEventWireup is set to false. So I would think that the control's server event function would NOT execute, but it does execute right after...
2
1419
by: Mike Curry | last post by:
I have run into a problem, I have 2 fields in my database, both key fields: Table 1 ===== Field X <key> Field Y <key> In field X, there are say about 3 records for each unique Field Y. I let my users query the data base like follows:
3
1800
by: Kentor | last post by:
hello, im trying to make a little loop, but i cant figure it out... i have a string with a bunch of 1s and 0s in it: 110101010101111010101 .... i need to count the number of 1s divide it by 2 and make a table with 2 columns and then for every one, depending on its position in the string i need to output a word and then go to the next 1 and output a dif word.... its amenities, winter activities and summer activities for cottages that i...
1
1760
by: durjoy | last post by:
dunno is the right forum to ask for help , but i cant see any category for html help . dont know any other site as well . this site is my last hope dear experts . i was hosting my site with different server than curent hosting however i have moved my site into new server and start having so many troubles . first of all couldnt figure out simple html error .. after successfuly moving site into new server i have checked every single page...
4
1528
by: rez151 | last post by:
trying to create a tree of hash nodes, with each node having a max of 5 objects, and a maximum of 5 child nodes...we insert 6 sucesfully and "explode" to create 3 child nodes, but when it gets to 7 our temp node has null pointers??? DRIVER PROGRAM:: #include <iostream> #include "MLH.h" using std::cout;
5
1876
by: chevon1920 | last post by:
I am trying to do my assignment but I cant figure out how to get 8 data points per line to print to a file. Here is the assignment 1. Program asks the user to enter an odd number as a BASE, using this Base it creates 48 multiples of the BASE and prints in a data file "data_3b.txt", 8-data per line. 2. Program opens this data file, scans the contents of "data_3b.txt" file and counts all the odd data, and prints them on the screen: 4 data...
1
1447
by: qwert7465 | last post by:
here is my code. i am only getting one error: // Final Project #include <iostream.h> #include <iomanip.h> void checkout(); void start_or_startover();
0
8413
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
8842
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...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7352
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
6176
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
5642
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();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.