Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: $(...).style is undefined - bug or my fault?

First hi everyone.. i just wanted to make a simple website for a friend and i thougt to add some effect.. but jeah.. first i wanted only to change the background of one element but then this came across:

TypeError: $(...).style is undefined (in the Firefox Console)

HTML:

<!DOCTYPE html>
<html lang="DE">
<head>
 <meta charset="utf-8"/>
 <title>Laura Sack - Offizielle Webseite</title>
</head>
<body>
 <div id="gallery-container" class="gallery-container cf"></div>
 <script src="js/jquery.js"></script>
 <script src="js/main.js"></script>
</body>
</html>

Javascript:

$(document).ready(function(){
   $("#gallery-container").style.background = "black";
});
like image 718
Steve Avatar asked May 24 '14 19:05

Steve


2 Answers

you are mixing javascript with jquery.

In jquery you have to use css() to make it work like this:

 $("#gallery-container").css("background","black");
like image 111
Ehsan Sajjad Avatar answered Oct 01 '22 16:10

Ehsan Sajjad


Try this,

$(document).ready(function(){
   $("#gallery-container").css('background-color','black');
});
like image 36
Rashmin Javiya Avatar answered Oct 01 '22 16:10

Rashmin Javiya