Reputation: 109
For some reason when I refer to the id "hi"(I know could've had a better name) in js it doesn't seem to recognize it. I think it has to do with the object itself.
var ChristmasHotel = {
var name: 'ChristmasHotel',
var rooms: 50,
getHotelName: function() {
return this.name;
}
};
var moreName = document.getElementById('hi');
moreName.textContent = ChristmasHotel.name;
<!DOCTYPE html>
<html>
<body>
<div>
<h1>Welcome to <span id='hi'>Null</span></h1>
</div>
</body>
</html
Upvotes: 0
Views: 36
Reputation: 22911
You have a few errors with your code:
</html>
tag was missing a closing >
.var
before when declaring keys.var ChristmasHotel = {
name : 'ChristmasHotel',
rooms : 50,
getHotelName : function(){
return this.name;
}
};
var moreName = document.getElementById('hi');
moreName.textContent = ChristmasHotel.name;
//You can also use:
moreName.textContent = ChristmasHotel.getHotelName();
<!DOCTYPE html>
<html>
<body>
<div>
<h1>Welcome to <span id = 'hi'>Null</span></h1>
</div>
</body>
</html>
Upvotes: 2