use jquery in global javascript function with browserify

30 Views Asked by At

I am trying to create a bundle file that will work like an embed script. I need jquery in it and I am trying it like this. I can use jQuery but I need to use a document. ready function. I was trying something better because There will be multiple places I need jQuery. Is there a better solution?

window.fmlead = (settings) => {
      const samplefunction = (samplearg) => {
        $(document).ready(function() {
          $("#main").html("Omg it is working");  // this is working
        })
        $("#main2").html("this is my tset"); // this is not working
      };
      const init = () => {
        samplefunction();
      };
    
      init();
    }

I tried this code as well but it doesn't work. It is giving me an error index.html:7 Uncaught ReferenceError: fmlead is not defined

$(document).ready(function () {
  window.fmlead = (settings) => {
    const samplefunction = (samplearg) => {
      $("#main2").html("this is my test"); // should work now
    };
    const init = () => {
      samplefunction();
    };

    init();
  };
});
0

There are 0 best solutions below