+ 7
how to call various javascript function into html
i have create a various js code with function. i want to call those function into html. how can i do that
46 odpowiedzi
+ 10
Look. Here’s the answer You make a button. That button looks like this:
<button onPress=“dostuff()”>CLICK HERE></button>
That means that on button press, whatever is in the quotes is Js and is runned. Now, in the JS code write:
function dostuff() {
//PUT ANY JS CODE YOU WANT HERE
}
the function do stuff is just a short way of saying everything that’s where ”//PUT ANY JS CODE YOU WANT HERE” is printed
understand?
+ 7
You can use HTML element attributes, for example:
<button onclick=handleClick()>Click me</button>
+ 7
Ipang
what of something like this
<!DOCTYPE html>
<html>
<body>
<h1>The onclick Event</h1>
<p>The onclick event is used to trigger a function when an element is clicked on.</p>
<p>Click the button to trigger a function that will output "Hello World" in a p element with id="demo".</p>
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";
}
</script>
</body>
</html>
+ 6
You need the script tag.
+ 5
♠👑 ℍⓄlʸᵇ𝕆𝒾 👍♦ check the JS tutorial. As already mentioned, the way you do it on code playground is different from when you write code outside SL.
+ 5
Check out this link:
http://www.simplehtmlguide.com/javascript.php
+ 5
♠👑 ℍⓄlʸᵇ𝕆𝒾 👍♦
Use event attributes to call them in html (search about it on google)
But I personally don't prefer to call functions in html! I prefer to use event listeners!
+ 5
Galaxy-Coding (CodeWarrior)
now think on when calling from diff file. you make much sense.thanks bro
+ 5
Include Js file in HTML then call the function by inline or event call.
+ 4
You can use a button to call your JS function
<button type="button" onclick="fun()">call function fun</button>
+ 4
♠👑 ℍⓄlʸᵇ𝕆𝒾 👍♦
In SoloLearn HTML, CSS and Javascript are written into sections in Code Playground editor. But if we work outside SoloLearn, HTML, CSS and Javascript codes can be written into separate files. Importing CSS or Javascript makes sense only when we work outside SoloLearn.
+ 3
Ipang explain in detail pls
+ 3
if that above code is correct.
Ipang two question arise there
(1) how can i import and execute js there.
(2)how can that be automatic.
if not explain deeper
+ 3
♠👑 ℍⓄlʸᵇ𝕆𝒾 👍♦
There are detailed answers to your question already as far as I understand your question.
If you need more help or want something explained in more detail, please also give more details on what we can help you with and where exactly you're stuck and what you have tried.
The script you sent for Ipang works as intended I guess. What was your question there?
What do you mean by import and execute?
And what do you want to be automatic?
+ 3
Sonic show an example pls,go to previous comment and see the code i made and then import js function for me
+ 3
Sonic how sir
+ 3
You can use script tag to load js code in html file
and you can use event attributes like on click , on drag
+ 3
<body onload="brython()">
<div id="board"></div>
</body>
like this then how do we connect the script with the js code
+ 3
<script src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.7.1/brython.min.js">
</script>
<script>
this is the script
+ 3
Your script tag should be in head otherwise it will give error
because, js must load before it is used