Converting Inline-javascript to Javascript

I shared the whole code at number #318 on here.

<ul class="test" class="hide">

Working code used this:

<ul id="myObj" class="hide">

So let’s try to understand the problem.

The test area is supposed to be hidden when the page starts, and the hide class is supposed to hide them.

Could it be that only the first of those two class attributes is being paid attention to? It is bad HTML to have duplicate attributes on an element. Put both test and hide together in just the one class attribute.

how?

By space-separating them in the same string.

<ul class="test, hide" >

Those are not space-separated. You have wrongly put a comma in there as well.

This works.

<ul class="test hide">

1 Like

Let’s work on this one next. Where do I start?

playButton4 is not defined. Clicking on that one.

Yes it is.

Okay, look at where playButton4 is being used.

<div class="playButton4">

.playButton4

Is there something wrong with how the CSS is being applied to it?

Is there something wrong in here?

<script>
  (function iife() {
    function playButton4ClickHandler() {
      var button = document.querySelector(".playButton4");
      var player = document.querySelector("#player4");
      player.volume = 1.0;
      if (player.paused) {
button.querySelector(".pause').style.display="inline-block";
button.querySelector(".play").style.display="none";
player.play();
} else {
button.querySelector(".play").style.display="inline-block";
button.querySelector(".pause").style.display="none";
player.pause();
      }
    }
    var playButton = document.querySelector(".playButton4");
    playButton4.addEventListener("click", playButton4ClickHandler);
 }());
</script>

Look at where playButton4 is being used.

Ooh, I notice something else too.

The coloring of the scripting code is all wrong. Do you see that?

It’s working now:

1 Like

.button div {

or

I get rid of the button if I use this.
.play, .pause{

Which way is preferred?

  .button div {
    position: absolute;
    width: 38px;
    height: 38px;
    top: 76px;
    left: 111px;
    background-color: transparent;
    background-size: 14px 18px;
    background-repeat: no-repeat;
    border-radius: 50%;
  }

or

  .play, .pause{
    position: absolute;
    width: 38px;
    height: 38px;
    top: 76px;
    left: 111px;
    background-color: transparent;
    background-size: 14px 18px;
    background-repeat: no-repeat;
    border-radius: 50%;
  }