0

Recently I made a archive box for my blog. Firstly I use style attribute for styling my list. But when I moved the css code in style attribute to a separate css file, my JS code didn't work. The following codes work fine when click the -> button.

the code that works fine

But when I use class of css instead of style attribute, the JS code doesnt't work. I cannot see the sub list items on the screen when I click the -> button. So I don't want to use style attribute. Because it easy to read style code from css file in my website. What can I do for handling this problem? Any suggestion?

the code that doesn't work

Note: Because "insert into post" button in code snippet tool doesn't work, I put codes as images into my post.

2
  • You should include a link to your jsfiddle next time, instead of pasting screenshots of jsfiddles. Commented Oct 4, 2014 at 5:43
  • Djd you try the technique called "debugging"? Commented Oct 4, 2014 at 6:49

1 Answer 1

1

It's because you're checking the style attribute, which you're not setting anymore. Just assume that the thing is not visible when you don't see a value since that's the default.

if (!months.style.display || months.style.display == "none") {
   months.style.display = "block";
}

After the first click the style attribute will have a value and it should work.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.