Adding javascript code

kirill14
3 Posts
kirill14 posted this 10 June 2020
Ask a Question

Hi i've made a form on a page. I want to be able to getelementsbyclass select the submit button via javascript and add for eg: console.log('hello'). I've added the JS file in a script tag to the HTML head, and inside it im trying to find the specific class of the button in question. However it keeps returning null and I'm unable to get the element and run a function on it.
Is there any way to do this?

Hi i've made a form on a page. I want to be able to getelementsbyclass select the submit button via javascript and add for eg: console.log('hello'). I've added the JS file in a script tag to the HTML head, and inside it im trying to find the specific class of the button in question. However it keeps returning null and I'm unable to get the element and run a function on it. Is there any way to do this?
Vote to pay developers attention to this features or issue.
6 Replies
Order By: Standard | Newest
Support Team
Support Team posted this 10 June 2020

Hi,

There is nothing specific to Nicepage at all. This example works ok if I change the first div to first Nicepage Button with "example" class:

https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_document_getelementsbyclassname

...................................................
Sincerely,
Olivia
Nicepage Support Team

Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1
Follow us on Facebook: http://facebook.com/nicepageapp

Hi, There is nothing specific to Nicepage at all. This example works ok if I change the first div to first Nicepage Button with "example" class: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_document_getelementsbyclassname ................................................... Sincerely, Olivia Nicepage Support Team Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1 Follow us on Facebook: http://facebook.com/nicepageapp
kirill14
3 Posts
kirill14 posted this 10 June 2020

Unfortunately this doesn't help, since i cant actually select any element in the DOM console when i run the page in chrome. If i try queryselector or elementbyclass or id, and try console log the result it brings back either undefined or an HTML collection which is an array with arbitrary stuff inside. Ive tried adding a class in the nicepage app for just a button, but even when i create a class and try call it, it gives me undefined even though i can see the element with the class in the DOM. The js is working properly if i declare variables in the js file i can see them defined in the console.

Unfortunately this doesn't help, since i cant actually select any element in the DOM console when i run the page in chrome. If i try queryselector or elementbyclass or id, and try console log the result it brings back either undefined or an HTML collection which is an array with arbitrary stuff inside. Ive tried adding a class in the nicepage app for just a button, but even when i create a class and try call it, it gives me undefined even though i can see the element with the class in the DOM. The js is working properly if i declare variables in the js file i can see them defined in the console.
Support Team
Support Team posted this 11 June 2020

Hello Kirill,

Could you please surround your code by the following snippet.

window.onload = function onload() {
    // Your code
}

...................................................
Sincerely,
Borys
Nicepage Support Team

Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1
Follow us on Facebook: http://facebook.com/nicepageapp

Hello Kirill, Could you please surround your code by the following snippet. window.onload = function onload() { // Your code } ................................................... Sincerely, Borys Nicepage Support Team Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1 Follow us on Facebook: http://facebook.com/nicepageapp
kirill14
3 Posts
kirill14 posted this 11 June 2020

Thank you that helped.

Thank you that helped.
ewheeler1225
2 Posts
ewheeler1225 posted this 09 July 2023

so to add the js code we just need to write it inside an html tag?

so to add the js code we just need to write it inside an html tag?
Support Team
Support Team posted this 10 July 2023

Hello Nave,

Yes, you can use it this way. Add tag inside the HTML element, and add JS code inside the script tag.

...................................................
Sincerely,
George.
Nicepage Support Team

Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1
Follow us on Facebook: http://facebook.com/nicepageapp

Hello Nave, Yes, you can use it this way. Add <script> </script> tag inside the HTML element, and add JS code inside the script tag. ................................................... Sincerely, George. Nicepage Support Team Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1 Follow us on Facebook: http://facebook.com/nicepageapp
You must log in or register to leave comments