How to load function if an ID exists on page

How to load function if an ID exists on page

Hello,

I have a basic question as a newbie.

I have a function

  1. function myFunction() {

        // function goes here
    }



I can call this every time in document.ready() or pageload(), however, the page i'm using it on has a number of panels which are shown in sequence, panel 1, then panel 2 etc. so I only want to call the function on panel 2. This panel contains a unique Id that I can reference, but how do I call this function when this selector exists?