Disclaimer: I came to Programmers.SE to ask this question because I understand this is the place to ask this type of question, and not necessarily stackoverflow. If I am wrong, please close the question and direct me to a place where I may be able to discuss it.
I have noticed that people have been saying (in the year 2014) that we aren't supposed to use JavaScript in the href
attribute of an HTML anchor tag. So then this function call:
<a id="expand-rail" href="javascript:callMyFunc()">Expand</a>
is discouraged, and over this it is preferred instead to attach an event handler to the onclick event of this anchor tag.
Why?
I'll take that this style of JavaScript function calls is very '90's, but what specific style guideline discusses this and weighs the pros and cons of doing it this was and recommends against it? I mean, there must be a pros and cons list, because I can think of some pros, like quick access to a function for a small HTML file, or easy readability on a small project. Yes, you have the cons, like not separating the view from the controller. I want to know who said this, why it is "generally understood", and where I can verify that.
Take something like this:
<span>
Please <a id="page-reload" href="javascript:window.location.reload()">click here</a> to refresh
</span>
It is abundantly obvious what I am trying to do. Is it really necessary to separate the logic from the view in this case? If you agree with me that we can let this one slide, then where do we draw the line?