File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Problem with unobtrusive JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Problem with unobtrusive JavaScript" Watch "Problem with unobtrusive JavaScript" New topic

Problem with unobtrusive JavaScript

Karim Kiswarday
Ranch Hand

Joined: Oct 01, 2010
Posts: 50

Hello rancheros,
I would like to ask you about a problem of unobtrusive javascript.

I know it's very good to separate behavior from structure but if I put events code in an external file for example, when in the future I will look again the HTML code, I will have problems to remember where my functions are invocate.

For example, if I have the below HTML code:

and in an external javascript file I have:

it's very difficult to know that pic1 has a javascript function.

How do you resolve this type of problem?


No fun at the table, no fun in the sack.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63845

You don't. If you don't want to keep the behavior separate from the structure, you don't want to use Unobtrusive JavaScript. It's kind of like asking how you can eat beef and still be a vegetarian.

The same thing applies to CSS. You can't see what styles are applied to the elements by just looking at the structure. You need to look at the CSS. In Unobtrusive JavaScript, you need to look at the script to know what behavior is applied.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Problem with unobtrusive JavaScript
It's not a secret anymore!