JavaScript JavaScript and the DOM Making Changes to the DOM Modifying Elements

Christopher Evans
Christopher Evans
9,776 Points

Can't get value of input using neither getElementById nor querySelector

I followed the example of the video given and have tried all combinations of querySelector/getElementById and "input", the ID, etc etc.

var inputValue = document.getElementById("linkName");
<!DOCTYPE html>
        <title>DOM Manipulation</title>
    <link rel="stylesheet" href="style.css" />
        <div id="content">
            <label>Link Name:</label>
            <input type="text" id="linkName">
            <a id="link" href=""></a>
        <script src="app.js"></script>

1 Answer

Dimitar Dimitrov
Dimitar Dimitrov
10,297 Points

you need the value of the input so .value after your selector will fix the problem.

var inputValue = document.getElementById("linkName").value;