Chuyển đến nội dung chính

Types of calling a function while click in javascript

     In javascript we can call a function while clicking html elements in three types, they are define in following example.

1) onclick
2) object.onclick
3) addEventListener


1) onclick:
     This is type is define inside the html tag. When you want to call a function in while clicking you can use the onclick attribute inside the html elements.

Syntax

<element onclick="script or function calling">


Example

<script>

 function cl_fun()

{

  alert("Function Called");

}

</script>



 <input type="button" onclick="cl_fun();" value="Click Here">


2) object.onclick
     In this method we are call a function using html elements id.

Syntax

var obj=document.getElementById("element_id");

obj.onclick=function(){/*script here*/};



Example

<script>

 var obj=document.getElementById("btnid");

 obj.onclick=function(){alert("Function Called");};



or

 var obj=document.getElementById("btnid");

 obj.onclick=function_name;

</script>



  <input type="button" id="btnid" value="Click Here">


3) addEventListener
     addEventListener also define such as object.onclick, the example is shown below.

Syntax:

 var obj=document.getElementById("element_id");

obj.addEventListener("click",function(){/*script here*/},useCapture);



 or

 var obj=document.getElementById("element_id");

 obj.addEventListener("click",function_name,useCapture);


addEventListener false why?
       The third parameter is If true, useCapture indicates that the user wishes to initiate capture. After initiating capture, all events of the specified type will be dispatched to the registered listener before being dispatched to any EventTargets beneath it in the DOM tree. Events which are bubbling upward through the tree will not trigger a listener designated to use capture. See DOM Level 3 Events for a detailed explanation.

Example

<script>

 var obj=document.getElementById("btnid");

 obj.addEventListener("click",function(){alert("Function Called"),false};

</script>



 <input type="button" id="btnid" value="Click Here">


Example Program:- (Editor)


Editor is Loading...

Advertisement




Tag:
click function using javascrip in allinworld99, click event in javascript allinworld99

Nhận xét

Popular Posts

Vectric Aspire 9.510 + Portable Free Download || FULL VERSION

Vectric Aspire 9.510 + Portable Free Download || FULL VERSION is here for your free direct with 100% working link from this place portablebull.blogspot.com. Description Vectric Aspire is a software company from Vectric Inc. in the CAM branch designed to design two and three-dimensional models for CNC router devices. The program is based on VCarve Pro's other proprietary software, with all the capabilities of the program in the field of modeling for CNC machines, as well as various tools for converting two-dimensional sketches, images, drawing, and digital arts into Auxiliary 3D models have high detail. After the initial conversion and final work done by the user, the software performs the three-dimensional calculations required to determine the cutting direction, and finally, using the CNC cutting machines, it produces cut-points and the final product. Vectric Aspire is used by many companies and companies for a wide range of products including decorativepanels, doors and windows,

Autodesk ArtCAM 2017 Crack + Patch + Full Version

Autodesk ArtCAM 2017 Crack + Patch + Full Version ArtCAM is, in fact, a design tool designed more for designers than engineers, and allows designers to showcase their creativity. The software delivers a CNC modeling CAD that can be used for a variety of industries. For example, designers of signs, woodcutters, jewelry designers and many others who can produce high-quality products before they can deliver their products in two-dimensional and three-dimensional form. It's easier with this software than ever. Features and Features of ArtCAM 2017 Crack + Patch + Full Version: Support for 64-bit systems Ability to mount jewelry pieces The ability to create complex shapes Ability to cut different pieces of pages The ability to create floating vectors Save layers and shapes that you must use Availability of ready-made models available System Requirements for ArtCAM 2017 full Crack for 2017, 2018: OS: Windows 7 SP1 / 8.x / 10 for 2012: Processor Type & Speed: Intel Core 2 Duo (or equiv

ABBYY FineReader 14.0.107.232 (32/64-bit) Free Full Download

Download ABBYY FineReader 14.0.107.232 (32/64-bit) Full Free Crack latest version offline setup for Microsoft Windows 7, 8, 10, XP, Vista. ABBYY FineReader v14.0.107.232 32-bit/64-bit Free Download is the best and fantastic a feature based on ABBYY (ORC) applications, These programs automatically convert electromagnetic electronics (images, bulletins, PDF files), you can also download free this software program for your PC/Computer. ABBYY FineReader 14.0.107.232 (32/64-bit) Overview ABBYY FineReader is easy and easy to use OCR software, changing PDFs is a positive alternative to entering or typing guide information. The ABBYY FineReader software is a great choice for professionals who want to deliver the best results for time and money. It provides strong performance for converting photos obtained from scanners, digital cameras or faxes, as variable and searchable text formats in PDF files. The ABBYY FineReader software supports broader formatting and document set, and broad languages