0

I have a JS code that creates the div (I created it with JS and not HTML for education purposes):

    var profile = document.createElement('div');
    .... some code...
    document.body.appendChild(profile);

Now in my css file that is associated with the main html file, I have this:

.profile{
    display: none;
}

This does not hide the profile div, and I do not understand why. I assume I am missing something in the CSS file, but after looking in the internet I did not find an answer.

2
  • 3
    profile is not class name it is variable Commented Dec 13, 2016 at 16:22
  • You need to target the <div> you created and apply the styling to it Commented Dec 13, 2016 at 16:29

3 Answers 3

2

Add this to your JS code:

var profile = document.createElement('div');
profile.className = 'profile';

Now the css can be applied to this element since it has a class called 'profile'

Sign up to request clarification or add additional context in comments.

Comments

2

Seems like your <div> does not have the class 'profile'

Have a look at this jsBin.

1 Comment

Thanks, I did not mark as the main response but I appreciate it and it helped me!
1

My advice would be next:

After this line var profile = document.createElement('div'); add a className selector to an element by this profile.className = "your class name here";

Then in CSS use this:

.your class name here{
    display: none;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.