[Solved] Call jquery tag in javascript function [closed]


You must have three things for your code to work:

  1. You must make sure to have the JQuery library referenced prior to your use of any JQuery code.
  2. In the HTML, you must have an element that is allowed to contain content with an add class.
  3. You must invoke your function somehow. Just writing a function isn’t the same thing as running it. You have to decide when the function should run and set up your code to invoke it at that point.

In the example below, the function is invoked every time the button is clicked.

document.querySelector("input[type=button]").addEventListener("click", addMoreAns);

function addMoreAns() {
  $(".add").append("<h1>Hi</h1>")
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" value="Click to Add">
<div class="add"></div>

solved Call jquery tag in javascript function [closed]