0

I want to get the value of an input field and put the value in between a paragraph and a <strong></strong> tag.

$(document).ready() {
  $("#submit").on("click", function() {
    let inputval = $("#name").val();
    $(".inputvalue").val(inputval);
  })
}
<!DOCTYPE html>
<html lang="de">

<head>
  <meta charset="UTF-8">
  <title>jQuery</title>
</head>

<body>
  <header>
    <h1>Jquery</h1>
  </header>
  <main>
    <section>
      <label for="name">Name</label>
      <input type="text" id="name">
      <input type="submit" id="submit">
      <p class="inputvalue">Hallo <strong>here goes the value of the input field</strong></p>
  </main>
  <link rel="stylesheet" href="/lib/css/styleswebd06.css">
  <script src="/lib/jquery.min.js"></script>
  <script src="/lib/js/appwebd06.js"></script>
</body>

</html>

i tried to get the value of the input field #name in class .inputvalue to geht the text hallo inputvalue

DarkBee
  • 16,592
  • 6
  • 46
  • 58

3 Answers3

0

Could you try this :

$(document).ready()
{

    $("#submit").on("click", function () {
        let inputval = $("#name").val();
        $(".inputvalue").html('HELLO <strong>' + inputval + '</strong>');
    })
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="de">
<head>  
    
    
    

    <meta charset="UTF-8">
    <title>jQuery</title>

</head>
<body>
<header><h1>Jquery</h1></header>
<main>
    <section>
        <label for="name">Name</label>
        <input type="text" id="name">
        <input type="submit" id="submit">
        <p class="inputvalue">Hallo <strong>here goes the value of the input field</strong></p>
</main>
<link rel="stylesheet" href="/lib/css/styleswebd06.css">
    <script src="/lib/jquery.min.js"></script>
        <script src="/lib/js/appwebd06.js"></script> 

</body>
</html>
SelVazi
  • 10,028
  • 2
  • 13
  • 29
0
$(".inputvalue strong").text(inputvalue);
freedomn-m
  • 27,664
  • 8
  • 35
  • 57
  • 1
    While this is technically correct, it could do with an explanation and, ideally, an updated snippet - use "copy snippet to answer" button and add your code along with an explanation. – freedomn-m Jan 04 '23 at 14:46
-1
$(".inputvalue").html('HELLO <strong>' + inputval + '</strong>');

Thank you very much.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31