5 Replies - 186 Views - Last Post: 13 August 2019 - 09:29 AM

#1 gorfl   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 13-August 19

add class from .css to index.html

Posted 13 August 2019 - 05:58 AM

Hi,
I am trying to do some exercises for beginners with jquery. and I am stuck in the beginning :)/>/>/>


the point of the exercise is to make a background color and then enter two text lines(<div>) and then make a colored square around every square.
The end product should look like this:

https://ibb.co/TvgCSPB



I have the following code in index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>jquery</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="funkcije.js"></script>
<link rel="stylesheet" href="slog.css" type="text/css" />
<style>

</style>

</head>
<body>
 	<div>don't worry</div>
	<div>be happy</div>
	
	
	
	
<script>
$( "div" ).first().addClass( "#one" );
</script>

</body>
</html>



and my .css looks like this
body {
  background-color: #ffe5af;
}


     div {
            width: 300px;
            height: 300px;
            margin: 20px;
            float: left;
        }


        #one {
            background-color: green;
        }

        #two {
            background-color: red;
        }








can someone help me out?

Is This A Good Question/Topic? 0
  • +

Replies To: add class from .css to index.html

#2 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6824
  • View blog
  • Posts: 31,469
  • Joined: 10-May 07

Re: add class from .css to index.html

Posted 13 August 2019 - 06:54 AM

You have created two div IDs, named one & two. To be classes they should be prefaced with a dot, rather than the pound symbol. Then in your html, the div tags have no class value.
Was This Post Helpful? 1
  • +
  • -

#3 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4244
  • View blog
  • Posts: 13,449
  • Joined: 08-June 10

Re: add class from .css to index.html

Posted 13 August 2019 - 06:56 AM

in CSS #one denotes an id, not a class.
Was This Post Helpful? 1
  • +
  • -

#4 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6823
  • View blog
  • Posts: 28,271
  • Joined: 12-December 12

Re: add class from .css to index.html

Posted 13 August 2019 - 07:08 AM

... although, when using addClass, you would not prepend the dot before the class name either.
Was This Post Helpful? 1
  • +
  • -

#5 gorfl   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 13-August 19

Re: add class from .css to index.html

Posted 13 August 2019 - 07:30 AM

thank you. works now :)
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6824
  • View blog
  • Posts: 31,469
  • Joined: 10-May 07

Re: add class from .css to index.html

Posted 13 August 2019 - 09:29 AM

Fantastic! Glad you got it corrected.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1