Today, We want to share with you how to call javascript function in html?.In this post we will show you onclick javascript, hear for calling external javascript function from html we will give you demo and example for implement.In this post, we will learn about call javascript function from html with an example.
how to call a function inside a function in javascript?
There are the Following The simple About call javascript function from html without event Full Information With Example and source code.
As I will cover this Post with live Working example to develop how to call a function in javascript, so the javascript call function by name is used for this example is following below.
Call a javascript function via html attribute
JS CODE
$('button').click(function(){ var data = $(this).attr('data-button-function'); //alert(data.name); eval(data); }); function testFunction(){ alert("test ok") }
Calling a Javascript Function with an Alert & Confirm Button in HTML
Change Things I
HelloGoodbye
JS CODE
function dochange(){ alert('You just clicked the fucking button with JS function'); } function confirmIt(){ var r = confirm("You just clicked the fucking confirm box"); if (r == true){ alert('You just fucking pressed OK'); } else { alert('Are you sure you want to fucking cancel'); } }
CSS CODE
h1 { background-color: green; } div { width: 200px; font-size: 28px; } #d1{ background-color: lightblue; } #d2{ background-color: yellow; }
jQuery on click call function with parameters
Click the buttons
Showing Div 1Showing Div2
JS CODE
$(document).ready(function() { $('.button').on('click', function() { var div_id = $(this).attr('data-div-id'); $('#div'+div_id).css('visibility', 'visible'); }); });
CSS CODE
/* DO NOT COPY*/ * { text-align: center;} .col-sm-6 { border: 1px dashed #21ba45;} .container { margin-top: 25px;} ._hidden { visibility: hidden; background-color: #21ba45; color: #ffffff; width: 100%; margin: 5px; } /* END DO NOT COPY*/
Web Programming Tutorials Example with Demo
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about how to call javascript function in html.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.