0

I have the following jQuery code in a project and I want to remove jQuery library from the project. So I am trying to convert this in to full javascript.

$(document).ready(function () {
    $("#price-button").click(priceButtonClicked), 
    getURLParameter("run") && $("#price-button").click()
});

var priceCell = $("#priceCell");

I tried this using document.getElementById but the issue is my page has not rendered and therefore the elements are not in present at that stage. I have no idea how to overcome this and any help would be greatly appreciated.

Berglund
  • 636
  • 2
  • 7
  • 20
  • 1
    Put your logic inside a window load event handler. Or include your script immediately before the `

    ` so the elements exist at the point the script runs.

    – Taplar May 06 '20 at 15:21
  • Either A) Use a [module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) (either relying on native support, or using a bundler like WebPack or Rollup), or B) Use `defer` on your `script` tag, or C) Put your `script` tag at the end of the document, just prior to the `

    ` tag. (In roughly that order of preference.)

    – T.J. Crowder May 06 '20 at 15:24

0 Answers0