Building a menu inside of ionic 4 progressive web application and I am using ajax /jquery to load pages into a div
. Is there any way to tell the jquery / to load the href src=
of the clicked element with the specific class. instead of adding this same code 20 times to load each different page
$('.classofButton').click ( function () {
$('#content').load ('href of clicked object or link etc') ;
} );
You can get the href by using this
$('.classofButton').click ( function () {
$('#content').load ($(this).attr('href')) ;
} );
You can do it like this.
$('.classofButton').click(function(event) { event.preventDefault(); var href = $(this).attr('href'); $('#content').load(href) ; });
#content { width: 200px; height: 200px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <a class="classofButton" href="http://google.com">google.com</a> <a class="classofButton" href="https://yahoo.com">yahoo.com</a> <div id="content"></div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.