I have this code to load the content from another file
$(document).ready(function(){
$("button").click(function(){
$("#divA").load("book.html #divB");
});
});
</script>
<button>Get</button>
This works, but I need the same thing with click on a link, instead of button
<a href="book.html">Get</a>
As per the user comment
I have another links on page. Only specific link should load the content.
Use the anchor tag as selector and make sure you stop the default action.
$(document).ready(function(e){
$("a#id").on('click',function(){ // $("a#id") or $("a.class") to target
// specific anchors
e.preventDefault();
$("#divA").load("book.html #divB");
});
});
Simply use a instead of button
$(document).ready(function(){
$("a").click(function(e){
e.preventDefault();
$("#divA").load("book.html #divB");
});
});
For specific a try this
$(document).ready(function(){
$("a#pass_your_id_here").click(function(e){
e.preventDefault();
$("#divA").load("book.html #divB");
});
});
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