Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Unobtrusive JavaScript avoids injecting inline JavaScript into HTML. This makes your HTML smaller and less cluttered, and makes it easier to swap out or customize JavaScript libraries

http://www.asp.net/mvc/mvc3#BM_JavaScript_and_Ajax_Improvements

what really is it ?( i am really trying to go deeper in the above article) can some one explain in simpler words

share|improve this question
    
Do either of the answer below answer your question? –  gingerbreadboy Jun 12 '13 at 10:39

2 Answers 2

instead of having onclick events defined on your elements like so

<a href="#" id="myId" onClick="myFunctionName()">Say Hi</a>

you push the binding out into you jscript file so your html looks more like...

<a href="#" id="myId" >Say Hi</a>

And in your code file... ( jquery for the example)

$('#myId').click(myFunctionName);

See this on Jquery...

This applies to everything, not just "click" events.

share|improve this answer
1  
In jQuery 1.7+ .On() is the recommended and consolidated way of binding events. $("#myId").on("click", function(event){ myFunctionName() }); –  lko Jun 5 '13 at 11:32
    
This is correct. JQuery has changed a lot in a few short years. –  gingerbreadboy Jun 5 '13 at 11:47

I get the impression from the things I've been reading and seeing is that it means more JS will be pulled out into external library files and not put inline in the HTML page.

I came across a good article by Brad Wilson that gives a good overview of Unobtrusive Javascript.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.