Reputation: 9855
I have a function I've written that I want to only execute on the click on an element...
$(document).ready(function () {
$(".black-sectors li a.adr-src").on("click", updateAddressDisplay);
updateAddressDisplay(null);
function updateAddressDisplay(src) {
# Function
}
});
The above is running on the page load however?
Upvotes: 0
Views: 408
Reputation: 36794
That'll be because you call it, right above where it's defined:
updateAddressDisplay(null); //Function called
function updateAddressDisplay(src) {
# Function
}
Remove updateAddressDisplay(null);
and it won't get called on page load.
Upvotes: 2
Reputation: 703
try removing updateAddressDisplay(null);
also you call pass some parameter with function on click call.
$(document).ready(function () {
$(".black-sectors li a.adr-src").on("click", updateAddressDisplay);
// updateAddressDisplay(null);
function updateAddressDisplay(src) {
# Function
}
});
Upvotes: 0