I am trying to call a the subSection
function both on onLoad and on click. But for some reason my code work only on On onClick but not on OnLoad and I am not sure why.
Here is my code:
fileOne.js
$(function () {
if ($('.MainSection .folderTab').length) {
subSection($('a.tab.present'));
// calling subSection() on Click.
$('.MainSection .folderTab a.tab').click(function() {
subSection($(this));
});
// calling subSection() on page load.
$('.MainSection .folderTab a.tab').on( "load", function() {
subSection($(this));
});
}
});
fileTwo.js
function subSection(element) {
// some code...
}
Currently on Click, the subSection
function get trigged properly and it works. But I also want to call the subSection
function on page load, and for some reason it not working. Am I not calling the function on page load correctly?
I have tried using the .on( "load", function()
or just calling the function directly like this: subSection($(this));
. But none of these approaches are triggering the function on page load.