I am trying to learn JavaScript, but my English is not that good.

While reading Simply JavaScript by Kevin Yank & Cameron Adams, I came across this paragraph, and I want to know what one sentence in it means:

Thanks to the wide adoption of the Document Object Model (DOM) standard, accessing HTML elements in your JavaScript code works very similarly in every browser. If only the same could be said for every aspect of JavaScript! As it happens, running JavaScript code in response to an event stands out as one of the few remaining features that are implemented in wildly varying ways in current browsers.

What does "If only the same could be said for every aspect of JavaScript!" mean?


Starting a sentence with "If only" indicates that one wishes the proceeding statement were true. That is, it would be nice if the statement made reflected reality.

For example:

If only everyone laughed at my jokes!


If only my love and I could be together!

So the person making this statement must have expressed some opinion about a certain aspect of JavaScript--e.g., JavaScript's mechanism for accessing DOM elements is consistent across major browsers--and then expressed the opinion, through the statement you've quoted, that this characteristic (cross-browser consistency) unfortunately does not hold for some other aspects of the language.

| improve this answer | |
  • actually sometimes it is much more than "it would be nice"; the phrase can be used for things that are crucial. – Unreason Jul 25 '11 at 7:59
  • 1
    You might also note that in "the same could be said", "the same" refers to something mentioned usually just previously. For example, if I say "Dan's writing is good. The same could be said about aedia's", I mean that aedia's writing is also good. But, "Dan's writing is good. If only the same could be said about aedia's!" means it is not true that aedia's writing is good, but I wish it were :) – aedia λ Jul 25 '11 at 15:30

The paragraph means the Javascript accesses the DOM standard well, across various browsers, but that other things you may try to do with Javascript will act differently in different browsers. The example of something that acts differently is the handling of events. IE may act differently than Chrome, and Firefox may act differently than either.

It is obviously desirable that Javascript code would run the same in ALL browsers, but sadly that is not the case. So you have to test your code in each browser, and even different versions of the same browser (for instance IE 10, and IE 11 may act differently)

It is a shame because the entire idea of Javascript is to run everywhere.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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