jQuery addClass example

Change class name on click in jQuery

by xDrago

HTML

<div id="banner-message">
<input type="text" id="inputVal">
  <p>Hello World</p>
  <p>hello world</p>
  <p>Hello Duke</p>
  <button id="btn">Button</button>
</div>

JavaScript

$('#btn').click( // if someone clicks the button
  function () {
    let input = $("#inputVal").val() //Takes the textbox textmy search text

    $("p:contains('" + input + "')").css("background-color", "yellow");

  });