0

I am trying to add a class to a div I create with javascript. I could append it inside another div with a class. This is the line of code in question.

  var car_storage = document.createElement('div');

I have tried using, the code below, but I get instead of a class this, "is[object, object]"

  var car_storage = document.createElement('div'{className: 'car_storage_cont'});

Please help.

Divern
  • 343
  • 2
  • 15

1 Answers1

0

You need to access className property. It is a string and you need to concatenate to it the new class's name.

car_storage .className += ' car_storage_cont';
Suren Srapyan
  • 66,568
  • 14
  • 114
  • 112
  • 1
    This is a very basic question and must have been answered many times. Please mark it duplicate – Rajesh Feb 21 '17 at 06:36
  • @Divern Please check dupes as they show more than 1 way with their benefits – Rajesh Feb 21 '17 at 06:41
  • @Rajesh, yeah, I just noticed that. My apologies. I am just new to javascript and didn't even know how it was called. – Divern Feb 21 '17 at 06:43
  • @Divern No need to apologies. We all are here to learn. Also, if refer to dupes and *accept/reject* based on merit so that no one else answers this question – Rajesh Feb 21 '17 at 06:45