How should I write the source code to change the color of the h1 text to the color selected in the pull-down menu? ??



  • Answer # 1

    Then I will answer.

    Answer example

    <! doctype html>
    <meta charset = "utf-8">
    function changeColor () {
      document.getElementById ("titleText"). style.color = document.getElementById ("textcolor"). value;
    <select id = "text color">
    <option value = "red">RED</option>
    <option value = "yellow">YELLOW</option>
    <option value = "pink">PINK</option>
    <option value = "green">GREEN</option>
    <option value = "black">BLACK</option>
    <option value = "purple">PURPLE</option>
    <button onclick = "changeColor ()">OK</button>

    I think this will work.

    Point 1
    Change color in the header
    onclick is changeColor
    Pay attention to the acronym for color

    Point 2
    document.getElementById ("textcolor"). value
    You can get the value in the select tag with.

    How is it?