Javascript-Unobtrusive - (6)

 


👉Unobtrusive Javascript


In web pages, we have presentation and behavior. Presentation is controlled by HTML and behavior is controlled by javascript.


<input type = "button" onclick = "Fun1();" id = btn1/>

<script language = javascript>

             Function Fun1()

                      {alert ("Hi");}

</script>


Here, button is tightly linked with the behavior. Unobtrusive javascript seperates presentation from behavior, making HTML more sleek.


<input type = "button"  id = btn1/>

<script src = "jscript1.js" type = "text/ javascript">

</script>


code of jscript1.js file:

<script language = "javascript">

           Function Fun1() {

                     alert("Hi");

            }

var e1 = document.getElementByID("btn1");

e1.onclick = Fun1();

</script>


As shown in the above example, using unobtrusive javascript, we will be able to change button's behavior anytime.

Comments

Popular posts from this blog

Javascript-OOPs(Part2)-AbstractionAndEncapsulation- (8)

Javascript-OOPs(Part4)-Polymorphism- (10)

Javascript-OOPs(Part1)-Objects - (7)