0

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?

3
  • 1
    Remove updateAddressDisplay(null); Commented Nov 5, 2013 at 11:11
  • 1
    Provide html too for better undeerstanding or else can you setup a jsfiddle Commented Nov 5, 2013 at 11:12
  • can you provide a jsfiddle? Commented Nov 5, 2013 at 11:22

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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
    }

});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.