I'm trying to make a website for my school, where you search for books through php, and when you click on a book it brings up a form to fill in a students info. However, when the JQuery runs when the document loads, the object I am trying to target is not in the page yet, this is because the page loads the object when the user types in the search bar. How do I delay the function until I have loaded the required objects?
Here is the code: HTML:
<section>
<img id="reading" src="img/reading.png" alt="person reading" />
<p>Any Book you want, at your Fingertips.</p>
<p class="subtext">Use the searchbar below to search for any book </br> in the Summerhill Library by name, author or ISBN.</p>
<input type"search" class='search' name='search' placeholder="Please enter Name, Author, ISBN or Catagory Number." onkeyup='searchq();'/>
</section>
<div class='results'>
<h2>Results</h2>
<div id='output'>
</div>
</div>
<div class='removeform'>
<h1>Book Lending</h1>
<!-- name -->
<p class='tagfullwidth'>Student Name</p>
<input class='fullwidthinput' type='text' />
<!-- bookname -->
<p class='tagfullwidth'>Book Name</p>
<input class='fullwidthinput book' type='text' />
<!-- yeardata -->
<div class='columns'>
<div class='column'>
<p class='tagfullwidth'>Year</p>
<input class='halfwidthinput' type='text' />
</div>
<div class='column'>
<p class='tagfullwidth textsecond'>Class</p>
<input class='halfwidthinput second' type='text' />
</div>
</div>
<!-- date -->
<div class='columns'>
<div class='column'>
<p class='tagfullwidth'>Today's Date</p>
<input class='halfwidthinput grey' type='date' />
</div>
<div class='column'>
<p class='tagfullwidth textsecond'>Expected Return Date</p>
<input class='halfwidthinput second grey' type='date' />
</div>
</div>
<!-- teachername -->
<p class='tagfullwidth'>Teacher Signature</p>
<input class='fullwidthinput' type='text' />
<!-- submit -->
<button class='scroll'>Submit Book Lend</button>
<p class='closebtn'>close</p>
</div>
CSS:
.removeform{
background-color:#fff;
width:1300px;
height:720px;
border-radius:20px;
margin:0 auto;
margin-top:100px;
position:fixed;
left: calc(50% - 650px);
visibility: hidden;
}
JQuery:
<script>
$('.post').click(function(){
$('.removeform').css('visibility','visible');
});
</script>