Would someone be able to help here?
I would like to fill a div e.g.
<div id="contenthere"></div>
with content from an external file e.g.
/includes/about-info.html
when a button with a certain class is clicked e.g.
<p class="classloader">Click Here</p>
Does anyone have a quick code example they can show me to achieve this?
Use jQuery.click
and jQuery.load
:
$(document).ready(function(){
$('.classloader.').click(function(){
$('#contenthere').load('/includes/about-info.html');
});
})
Load latest version of jQuery:
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
jQuery code:
<script language="javascript">
$(function(){
$(".classloader").click(function(){
$("#contenthere").load("/includes/about-info.html");
});
});
</script>
HTML code:
<p class="classloader">Click Here</p>
<div id="contenthere"></div>
You could subscribe to the .click()
event of the paragraph and then use the .load()
function to send an AJAX request to the given url and inject the results into the specified selector:
$(function() {
$('.classloader').click(function() {
$('#contenthere').load('/includes/about-info.html');
return false;
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With