JQuery addClass to DIV not working? (Beginner question)

Hi i am a beginner with JQUery i am trying to add a Class… to a excisting DIV but for some reason it’s not working neither do i get a error… can somebody help?

THanks :smiley:

<!doctype html>
<html>
<head>
<title>Test App</title>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>

<style>
#banner {
background: #EEE;
width: 500px;
min-height: 250px;
margin: 0 auto;
}

.red-box {
display: block;
height: 50px;
width: 50px;
background: red;
}
</style>

<script>
$(document).ready(function(){
$("#banner").find("p").addClass(".red-box");
}
</script>

<section id="banner">
<p>Font-weight</p>
</section>

</head>
</html>

You have no <body></body>.

Also with addClass() you don’t need to have the period in front of red-box. Just do addClass(“red-box”)

1 Like

$(“#banner”).find(“p”).addClass(“red-box”);
});

use above code it should work.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.