So what I'm trying to do is make a script that will show and hide the title of YouTube videos and all my script seems to be doing is setting it default to display none which I don't want it to do that and it seems as if the onclick function isn't even working either. I honestly cannot figure out what I did wrong... everything seems like it should work.

Here's the script:

function titleToggle() {
    eowTitle = document.getElementById('eow-title');
    watch7Headline = document.getElementById('watch7-headline');
    eowTitle.style.display = 'inline-block';
    (eowTitle.style.display == 'none') ? watch7Headline.onclick = eowTitle.style.display = 'inline-block' : watch7Headline.onclick = eowTitle.style.display = 'none';
}
titleToggle();
有帮助吗?

解决方案

You need to set the "onclick" property to a function. If you really want to use ? :, you'd be better off doing this:

watch7Headline.onclick = function() {
  eowTitle.style.display = (eowTitle.style.display == 'none') ? 'inline-block' : 'none';
};
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top